You can subscribe to this list here.
| 2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(31) |
Sep
|
Oct
|
Nov
(26) |
Dec
(5) |
|---|
|
From: <sch...@us...> - 2008-12-22 23:23:44
|
Revision: 62
http://deraciel.svn.sourceforge.net/deraciel/?rev=62&view=rev
Author: schnippi001
Date: 2008-12-22 23:23:35 +0000 (Mon, 22 Dec 2008)
Log Message:
-----------
Text window clears after keypress
Modified Paths:
--------------
trunk/GUI.h
trunk/NCursesGUI.cpp
trunk/NCursesGUI.h
trunk/NCursesTextWindow.cpp
trunk/main.cpp
Modified: trunk/GUI.h
===================================================================
--- trunk/GUI.h 2008-12-22 22:09:46 UTC (rev 61)
+++ trunk/GUI.h 2008-12-22 23:23:35 UTC (rev 62)
@@ -16,6 +16,7 @@
public:
virtual void initialize() = 0;
virtual void finalize() = 0;
+ virtual void update() = 0;
virtual TextWindow *getTextWindow() = 0;
virtual MapWindow *getMapWindow() = 0;
virtual StatusWindow *getStatusWindow() = 0;
Modified: trunk/NCursesGUI.cpp
===================================================================
--- trunk/NCursesGUI.cpp 2008-12-22 22:09:46 UTC (rev 61)
+++ trunk/NCursesGUI.cpp 2008-12-22 23:23:35 UTC (rev 62)
@@ -35,6 +35,10 @@
endwin();
}
+void NCursesGUI::update() {
+ doupdate();
+}
+
TextWindow *NCursesGUI::getTextWindow() {
return textWindow;
}
Modified: trunk/NCursesGUI.h
===================================================================
--- trunk/NCursesGUI.h 2008-12-22 22:09:46 UTC (rev 61)
+++ trunk/NCursesGUI.h 2008-12-22 23:23:35 UTC (rev 62)
@@ -14,6 +14,7 @@
public:
void initialize();
void finalize();
+ void update();
TextWindow *getTextWindow();
MapWindow *getMapWindow();
StatusWindow *getStatusWindow();
Modified: trunk/NCursesTextWindow.cpp
===================================================================
--- trunk/NCursesTextWindow.cpp 2008-12-22 22:09:46 UTC (rev 61)
+++ trunk/NCursesTextWindow.cpp 2008-12-22 23:23:35 UTC (rev 62)
@@ -44,6 +44,9 @@
/* Redraw border with new dimensions */
drawBorder();
}
+
+ wnoutrefresh(borderWindow);
+ wnoutrefresh(textWindow);
}
void NCursesTextWindow::displayString(const string string) {
Modified: trunk/main.cpp
===================================================================
--- trunk/main.cpp 2008-12-22 22:09:46 UTC (rev 61)
+++ trunk/main.cpp 2008-12-22 23:23:35 UTC (rev 62)
@@ -20,7 +20,8 @@
gui = new NCursesGUI();
gui->initialize();
- //gui->getStatusWindow->displayStatus();
+ gui->getStatusWindow()->displayStatus();
+ gui->update();
/* Assign key handler callback */
KeyboardReader::setKeyboardHandler(keyhandler);
@@ -37,6 +38,9 @@
}
static void keyhandler(const int key) {
+ gui->getTextWindow()->clear();
+ gui->getStatusWindow()->displayStatus();
+
if (key == KEY_ESCAPE) {
// Stop keyboard handler loop
KeyboardReader::stop();
@@ -51,23 +55,9 @@
refresh();
}
- if (key == KEY_UP) {
- cout << "KEY_UP" << endl;
- }
-
- if (key == KEY_DOWN) {
- cout << "KEY_DOWN" << endl;
- }
-
- if (key == KEY_LEFT) {
- cout << "KEY_LEFT" << endl;
- }
-
- if (key == KEY_RIGHT) {
- cout << "KEY_RIGHT" << endl;
- }
-
if (key == 'm') {
- //gui->getTextWindow->displayString("Message displayed");
+ gui->getTextWindow()->displayString("Message displayed");
}
+
+ gui->update();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sch...@us...> - 2008-12-22 23:22:42
|
Revision: 59
http://deraciel.svn.sourceforge.net/deraciel/?rev=59&view=rev
Author: schnippi001
Date: 2008-12-22 21:37:44 +0000 (Mon, 22 Dec 2008)
Log Message:
-----------
GUI abstraction with interfaces
Modified Paths:
--------------
trunk/cpp/CMakeLists.txt
trunk/cpp/KeyboardReader.h
trunk/cpp/MapWindow.h
trunk/cpp/StatusWindow.h
trunk/cpp/TextWindow.h
trunk/cpp/main.cpp
Added Paths:
-----------
trunk/cpp/NCursesMapWindow.cpp
trunk/cpp/NCursesMapWindow.h
trunk/cpp/NCursesStatusWindow.cpp
trunk/cpp/NCursesStatusWindow.h
trunk/cpp/NCursesTextWindow.cpp
trunk/cpp/NCursesTextWindow.h
Removed Paths:
-------------
trunk/cpp/MapWindow.cpp
trunk/cpp/StatusWindow.cpp
trunk/cpp/TextWindow.cpp
Modified: trunk/cpp/CMakeLists.txt
===================================================================
--- trunk/cpp/CMakeLists.txt 2008-12-04 10:06:31 UTC (rev 58)
+++ trunk/cpp/CMakeLists.txt 2008-12-22 21:37:44 UTC (rev 59)
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 2.6)
project(deraciel)
-SET(CMAKE_CXX_FLAGS "-Wall -Werror")
+SET(CMAKE_CXX_FLAGS "-Wall -Werror -g")
# requirements
find_library( NCURSES_LIBRARY ncurses )
Modified: trunk/cpp/KeyboardReader.h
===================================================================
--- trunk/cpp/KeyboardReader.h 2008-12-04 10:06:31 UTC (rev 58)
+++ trunk/cpp/KeyboardReader.h 2008-12-22 21:37:44 UTC (rev 59)
@@ -1,11 +1,11 @@
class KeyboardReader {
- public:
- static void setKeyboardHandler(void (*handler)(const int key));
- static void startLoop();
- static void stop();
+public:
+ static void setKeyboardHandler(void (*handler)(const int key));
+ static void startLoop();
+ static void stop();
- private:
- static void (*keyboardHandler)(const int key);
- static bool keyboardReaderActive;
+private:
+ static void (*keyboardHandler)(const int key);
+ static bool keyboardReaderActive;
};
\ No newline at end of file
Deleted: trunk/cpp/MapWindow.cpp
===================================================================
--- trunk/cpp/MapWindow.cpp 2008-12-04 10:06:31 UTC (rev 58)
+++ trunk/cpp/MapWindow.cpp 2008-12-22 21:37:44 UTC (rev 59)
@@ -1,49 +0,0 @@
-#include "MapWindow.h"
-
-#include <iostream>
-#include <string>
-#include <ncurses.h>
-
-using namespace std;
-
-MapWindow::MapWindow() {
- window = newwin(maxHeight, maxWidth, 2, 0);
-
- if (!window) {
- cerr << "Error: Map window creation failed!" << endl;
- return;
- }
-
- wattron(window, COLOR_PAIR(4));
- wbkgd(window, COLOR_PAIR(4));
-
- wrefresh(window);
-}
-
-
-
-MapWindow::~MapWindow() {
- /* Free resources consumed by windows */
- delwin(window);
-}
-
-
-
-void MapWindow::resize() {
- /* Reallocate storage for resized text window */
- wresize(window, maxHeight, maxWidth);
-}
-
-
-
-void MapWindow::displayMap(const chtype *map) {
- /* Set cursor to first position (upper left) in map window */
- wmove(window, 0, 0);
-
- /* Copy map to local map */
- for (unsigned int s = 0; s < screensize; s++) {
- waddch(window, map[s]);
- }
-
- wnoutrefresh(window);
-}
Modified: trunk/cpp/MapWindow.h
===================================================================
--- trunk/cpp/MapWindow.h 2008-12-04 10:06:31 UTC (rev 58)
+++ trunk/cpp/MapWindow.h 2008-12-22 21:37:44 UTC (rev 59)
@@ -1,17 +1,20 @@
-#include <string>
-#include <ncurses.h>
+/*
+ * File: MapWindow.h
+ * Author: schnippi
+ *
+ * Created on 22. Dezember 2008, 20:47
+ */
+#ifndef _MAPWINDOW_H
+#define _MAPWINDOW_H
+
+#include "Map.h"
+
class MapWindow {
- public:
- MapWindow();
- ~MapWindow();
- void draw();
- void resize();
- void displayMap(const chtype *map);
+public:
+ virtual void resize() = 0;
+ virtual void displayMap(const Map *map) = 0;
+};
- private:
- WINDOW *window; // Window handle
- static const unsigned int maxWidth = 80; // Maximum window width
- static const unsigned int maxHeight = 20; // Maximum window height
- static const unsigned int screensize = maxWidth * maxHeight;
-};
\ No newline at end of file
+#endif /* _MAPWINDOW_H */
+
Copied: trunk/cpp/NCursesMapWindow.cpp (from rev 56, trunk/cpp/MapWindow.cpp)
===================================================================
--- trunk/cpp/NCursesMapWindow.cpp (rev 0)
+++ trunk/cpp/NCursesMapWindow.cpp 2008-12-22 21:37:44 UTC (rev 59)
@@ -0,0 +1,38 @@
+#include "NCursesMapWindow.h"
+
+#include <iostream>
+#include <string>
+#include <ncurses.h>
+
+using namespace std;
+
+NCursesMapWindow::NCursesMapWindow() {
+ window = newwin(maxHeight, maxWidth, 2, 0);
+
+ if (!window) {
+ cerr << "Error: Map window creation failed!" << endl;
+ return;
+ }
+
+ wattron(window, COLOR_PAIR(4));
+ wbkgd(window, COLOR_PAIR(4));
+
+ wrefresh(window);
+}
+
+NCursesMapWindow::~NCursesMapWindow() {
+ /* Free resources consumed by windows */
+ delwin(window);
+}
+
+void NCursesMapWindow::resize() {
+ /* Reallocate storage for resized text window */
+ wresize(window, maxHeight, maxWidth);
+}
+
+void NCursesMapWindow::displayMap(const Map *map) {
+ /* Set cursor to first position (upper left) in map window */
+ wmove(window, 0, 0);
+
+ wnoutrefresh(window);
+}
Property changes on: trunk/cpp/NCursesMapWindow.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Copied: trunk/cpp/NCursesMapWindow.h (from rev 56, trunk/cpp/MapWindow.h)
===================================================================
--- trunk/cpp/NCursesMapWindow.h (rev 0)
+++ trunk/cpp/NCursesMapWindow.h 2008-12-22 21:37:44 UTC (rev 59)
@@ -0,0 +1,18 @@
+#include <string>
+#include <ncurses.h>
+
+#include "MapWindow.h"
+
+class NCursesMapWindow : public MapWindow {
+public:
+ NCursesMapWindow();
+ ~NCursesMapWindow();
+ void resize();
+ void displayMap(const Map *map);
+
+private:
+ WINDOW *window; // Window handle
+ static const unsigned int maxWidth = 80; // Maximum window width
+ static const unsigned int maxHeight = 20; // Maximum window height
+ static const unsigned int screensize = maxWidth * maxHeight;
+};
Property changes on: trunk/cpp/NCursesMapWindow.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Copied: trunk/cpp/NCursesStatusWindow.cpp (from rev 56, trunk/cpp/StatusWindow.cpp)
===================================================================
--- trunk/cpp/NCursesStatusWindow.cpp (rev 0)
+++ trunk/cpp/NCursesStatusWindow.cpp 2008-12-22 21:37:44 UTC (rev 59)
@@ -0,0 +1,54 @@
+#include "NCursesStatusWindow.h"
+
+#include <iostream>
+#include <string>
+#include <ncurses.h>
+
+using namespace std;
+
+NCursesStatusWindow::NCursesStatusWindow() {
+ window = newwin(maxHeight, maxWidth, 25 - maxHeight, 0);
+
+ if (!window) {
+ cerr << "Error: Status window creation failed!" << endl;
+ return;
+ }
+
+ wattron(window, COLOR_PAIR(3));
+ wbkgd(window, COLOR_PAIR(3));
+
+ wrefresh(window);
+}
+
+NCursesStatusWindow::~NCursesStatusWindow() {
+ /* Free resources consumed by window */
+ delwin(window);
+}
+
+void NCursesStatusWindow::resize() {
+ /* Reallocate storage for resized text window */
+ wresize(window, maxHeight, maxWidth);
+}
+
+void NCursesStatusWindow::displayStatus() {
+ if (borderIsDrawn) {
+ /* Redraw border */
+ drawBorder();
+ }
+
+ mvwprintw(window, 1, 2, "$:%d HP:%d(%d) MP:%d(%d) St:%2d Dx:%2d Co:%2d Wi:%2d Wp:%2d Ch:%2d",
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+
+ mvwprintw(window, 2, 2, "%s Xp:%2d/%d T:%d S:%d",
+ "Deraciel", 0, 1, 2, 3);
+
+ wnoutrefresh(window);
+}
+
+/*
+ Private member function declarations
+ */
+
+void NCursesStatusWindow::drawBorder() {
+ wborder(window, 0, 0, 0, ' ', '/', '\\', ACS_VLINE, ACS_VLINE);
+}
Property changes on: trunk/cpp/NCursesStatusWindow.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Copied: trunk/cpp/NCursesStatusWindow.h (from rev 56, trunk/cpp/StatusWindow.h)
===================================================================
--- trunk/cpp/NCursesStatusWindow.h (rev 0)
+++ trunk/cpp/NCursesStatusWindow.h 2008-12-22 21:37:44 UTC (rev 59)
@@ -0,0 +1,19 @@
+#include <string>
+#include <ncurses.h>
+
+#include "StatusWindow.h"
+
+class NCursesStatusWindow : public StatusWindow {
+public:
+ NCursesStatusWindow();
+ ~NCursesStatusWindow();
+ void resize();
+ void displayStatus();
+
+private:
+ WINDOW *window; // Window handle
+ static const unsigned int maxWidth = 80; // Maximum window width
+ static const unsigned int maxHeight = 3; // Maximum window height
+ static const bool borderIsDrawn = true; // Draw window borders by default
+ void drawBorder();
+};
\ No newline at end of file
Property changes on: trunk/cpp/NCursesStatusWindow.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Copied: trunk/cpp/NCursesTextWindow.cpp (from rev 56, trunk/cpp/TextWindow.cpp)
===================================================================
--- trunk/cpp/NCursesTextWindow.cpp (rev 0)
+++ trunk/cpp/NCursesTextWindow.cpp 2008-12-22 21:37:44 UTC (rev 59)
@@ -0,0 +1,68 @@
+#include "NCursesTextWindow.h"
+
+#include <iostream>
+#include <string>
+#include <ncurses.h>
+
+using namespace std;
+
+NCursesTextWindow::NCursesTextWindow() {
+ borderWindow = newwin(maxHeight, maxWidth, 0, 0);
+ textWindow = newwin(maxHeight - 1, maxWidth - 2, 0, 1);
+
+ if (!borderWindow || !textWindow) {
+ cerr << "Error: Text window creation failed!" << endl;
+ return;
+ }
+
+ wattron(borderWindow, COLOR_PAIR(1));
+ wbkgd(textWindow, COLOR_PAIR(1));
+
+ if (borderIsDrawn) {
+ /* Redraw border with new dimensions */
+ drawBorder();
+ }
+
+ wrefresh(borderWindow);
+ wrefresh(textWindow);
+}
+
+NCursesTextWindow::~NCursesTextWindow() {
+ /* Free resources consumed by windows */
+ delwin(borderWindow);
+ delwin(textWindow);
+}
+
+void NCursesTextWindow::resize() {
+ /* Reallocate storage for resized text window */
+ wresize(borderWindow, maxHeight, maxWidth);
+ wresize(textWindow, maxHeight - 1, maxWidth);
+}
+
+void NCursesTextWindow::clear() {
+ if (borderIsDrawn) {
+ /* Redraw border with new dimensions */
+ drawBorder();
+ }
+}
+
+void NCursesTextWindow::displayString(const string string) {
+ if (borderIsDrawn) {
+ /* Redraw border*/
+ drawBorder();
+ }
+
+ wmove(textWindow, 0, 0);
+ wprintw(textWindow, string.c_str());
+
+ wnoutrefresh(borderWindow);
+ wnoutrefresh(textWindow);
+}
+
+/*
+ Private member function declarations
+ */
+
+void NCursesTextWindow::drawBorder() {
+ wborder(borderWindow, 0, 0, ' ', 0, ACS_VLINE, ACS_VLINE, '\\', '/');
+}
\ No newline at end of file
Property changes on: trunk/cpp/NCursesTextWindow.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Copied: trunk/cpp/NCursesTextWindow.h (from rev 56, trunk/cpp/TextWindow.h)
===================================================================
--- trunk/cpp/NCursesTextWindow.h (rev 0)
+++ trunk/cpp/NCursesTextWindow.h 2008-12-22 21:37:44 UTC (rev 59)
@@ -0,0 +1,21 @@
+#include <string>
+#include <ncurses.h>
+
+#include "TextWindow.h"
+
+class NCursesTextWindow : public TextWindow {
+public:
+ NCursesTextWindow();
+ ~NCursesTextWindow();
+ void resize();
+ void clear();
+ void displayString(const std::string string);
+
+private:
+ WINDOW *borderWindow; // Window handle
+ WINDOW *textWindow; // Window handle
+ static const unsigned int maxWidth = 80; // Maximum window width
+ static const unsigned int maxHeight = 2; // Maximum window height
+ static const bool borderIsDrawn = true; // Draw window borders by default
+ void drawBorder();
+};
Property changes on: trunk/cpp/NCursesTextWindow.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Deleted: trunk/cpp/StatusWindow.cpp
===================================================================
--- trunk/cpp/StatusWindow.cpp 2008-12-04 10:06:31 UTC (rev 58)
+++ trunk/cpp/StatusWindow.cpp 2008-12-22 21:37:44 UTC (rev 59)
@@ -1,62 +0,0 @@
-#include "StatusWindow.h"
-
-#include <iostream>
-#include <string>
-#include <ncurses.h>
-
-using namespace std;
-
-StatusWindow::StatusWindow() {
- window = newwin(maxHeight, maxWidth, 25-maxHeight, 0);
-
- if (!window) {
- cerr << "Error: Status window creation failed!" << endl;
- return;
- }
-
- wattron(window, COLOR_PAIR(3));
- wbkgd(window, COLOR_PAIR(3));
-
- wrefresh(window);
-}
-
-
-
-StatusWindow::~StatusWindow() {
- /* Free resources consumed by window */
- delwin(window);
-}
-
-
-
-void StatusWindow::resize() {
- /* Reallocate storage for resized text window */
- wresize(window, maxHeight, maxWidth);
-}
-
-
-
-void StatusWindow::displayStatus() {
- if (borderIsDrawn) {
- /* Redraw border */
- drawBorder();
- }
-
- mvwprintw(window, 1, 2, "$:%d HP:%d(%d) MP:%d(%d) St:%2d Dx:%2d Co:%2d Wi:%2d Wp:%2d Ch:%2d",
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
-
- mvwprintw(window, 2, 2, "%s Xp:%2d/%d T:%d S:%d",
- "Deraciel", 0, 1, 2, 3);
-
- wnoutrefresh(window);
-}
-
-
-
-/*
- Private member function declarations
-*/
-
-void StatusWindow::drawBorder() {
- wborder(window, 0, 0, 0, ' ', '/', '\\', ACS_VLINE, ACS_VLINE);
-}
Modified: trunk/cpp/StatusWindow.h
===================================================================
--- trunk/cpp/StatusWindow.h 2008-12-04 10:06:31 UTC (rev 58)
+++ trunk/cpp/StatusWindow.h 2008-12-22 21:37:44 UTC (rev 59)
@@ -1,17 +1,19 @@
-#include <string>
-#include <ncurses.h>
+/*
+ * File: StatusWindow.h
+ * Author: schnippi
+ *
+ * Created on 22. Dezember 2008, 20:47
+ */
+#ifndef _STATUSWINDOW_H
+#define _STATUSWINDOW_H
+
class StatusWindow {
- public:
- StatusWindow();
- ~StatusWindow();
- void resize();
- void displayStatus(void);
+public:
+ virtual void resize() = 0;
+ virtual void displayStatus() = 0;
+};
- private:
- WINDOW *window; // Window handle
- static const unsigned int maxWidth = 80; // Maximum window width
- static const unsigned int maxHeight = 3; // Maximum window height
- static const bool borderIsDrawn = true; // Draw window borders by default
- void drawBorder();
-};
\ No newline at end of file
+
+#endif /* _STATUSWINDOW_H */
+
Deleted: trunk/cpp/TextWindow.cpp
===================================================================
--- trunk/cpp/TextWindow.cpp 2008-12-04 10:06:31 UTC (rev 58)
+++ trunk/cpp/TextWindow.cpp 2008-12-22 21:37:44 UTC (rev 59)
@@ -1,68 +0,0 @@
-#include "TextWindow.h"
-
-#include <iostream>
-#include <string>
-#include <ncurses.h>
-
-using namespace std;
-
-TextWindow::TextWindow() {
- borderWindow = newwin(maxHeight, maxWidth, 0, 0);
- textWindow = newwin(maxHeight-1, maxWidth-2, 0, 1);
-
- if (!borderWindow || !textWindow) {
- cerr << "Error: Text window creation failed!" << endl;
- return;
- }
-
- wattron(borderWindow, COLOR_PAIR(1));
- wbkgd(textWindow, COLOR_PAIR(1));
-
- if (borderIsDrawn) {
- /* Redraw border with new dimensions */
- drawBorder();
- }
-
- wrefresh(borderWindow);
- wrefresh(textWindow);
-}
-
-
-
-TextWindow::~TextWindow() {
- /* Free resources consumed by windows */
- delwin(borderWindow);
- delwin(textWindow);
-}
-
-
-
-void TextWindow::resize() {
- /* Reallocate storage for resized text window */
- wresize(borderWindow, maxHeight, maxWidth);
- wresize(textWindow, maxHeight-1, maxWidth);
-}
-
-
-
-void TextWindow::displayString(const string string) {
- if (borderIsDrawn) {
- /* Redraw border*/
- drawBorder();
- }
-
- wmove(textWindow, 0, 0);
- wprintw(textWindow, string.c_str());
-
- wnoutrefresh(borderWindow);
- wnoutrefresh(textWindow);
-}
-
-
-/*
- Private member function declarations
-*/
-
-void TextWindow::drawBorder() {
- wborder(borderWindow, 0, 0, ' ', 0, ACS_VLINE, ACS_VLINE, '\\', '/');
-}
\ No newline at end of file
Modified: trunk/cpp/TextWindow.h
===================================================================
--- trunk/cpp/TextWindow.h 2008-12-04 10:06:31 UTC (rev 58)
+++ trunk/cpp/TextWindow.h 2008-12-22 21:37:44 UTC (rev 59)
@@ -1,19 +1,21 @@
+/*
+ * File: TextWindow.h
+ * Author: schnippi
+ *
+ * Created on 22. Dezember 2008, 04:28
+ */
+
+#ifndef _DERACIEL_TEXTWINDOW_H
+#define _DERACIEL_TEXTWINDOW_H
+
#include <string>
-#include <ncurses.h>
class TextWindow {
- public:
- TextWindow();
- ~TextWindow();
- void resize();
- void clear();
- void displayString(const std::string string);
+public:
+ virtual void resize() = 0;
+ virtual void clear() = 0;
+ virtual void displayString(const std::string string) = 0;
+};
- private:
- WINDOW *borderWindow; // Window handle
- WINDOW *textWindow; // Window handle
- static const unsigned int maxWidth = 80; // Maximum window width
- static const unsigned int maxHeight = 2; // Maximum window height
- static const bool borderIsDrawn = true; // Draw window borders by default
- void drawBorder();
-};
\ No newline at end of file
+
+#endif /* _DERACIEL_TEXTWINDOW_H */
Modified: trunk/cpp/main.cpp
===================================================================
--- trunk/cpp/main.cpp 2008-12-04 10:06:31 UTC (rev 58)
+++ trunk/cpp/main.cpp 2008-12-22 21:37:44 UTC (rev 59)
@@ -2,9 +2,7 @@
#include <signal.h>
#include <ncurses.h>
-#include "TextWindow.h"
-#include "MapWindow.h"
-#include "StatusWindow.h"
+#include "NCursesGUI.h"
#include "KeyboardReader.h"
using namespace std;
@@ -14,83 +12,62 @@
static void finish(const int signum);
static void keyhandler(const int key);
+GUI *gui;
+
int main(int argc, char **argv) {
- signal(SIGINT, finish); /* arrange interrupts to terminate */
- initscr(); /* initialize the curses library */
- keypad(stdscr, TRUE); /* enable keyboard mapping */
- nonl(); /* tell curses not to do NL->CR/NL on output */
- //cbreak(); /* take input chars one at a time, no wait for \n */
- noecho(); /* don't echo input */
+ signal(SIGINT, finish); /* arrange interrupts to terminate */
- curs_set(0); /* Hide the cursor */
+ gui = new NCursesGUI();
+ gui->initialize();
- start_color();
- init_pair(1, COLOR_WHITE, COLOR_BLUE);
- init_pair(2, COLOR_BLACK, COLOR_YELLOW);
- init_pair(3, COLOR_WHITE, COLOR_RED);
- init_pair(4, COLOR_WHITE, COLOR_GREEN);
+ //gui->getStatusWindow->displayStatus();
- clear();
- refresh();
+ /* Assign key handler callback */
+ KeyboardReader::setKeyboardHandler(keyhandler);
- TextWindow textWindow;
- MapWindow mapWindow;
- StatusWindow statusWindow;
+ /* Start keyboard handler loop */
+ KeyboardReader::startLoop();
- statusWindow.displayStatus();
-
- //invt_init(&main_char.inventory);
-
- /* Assign key handler callback */
- KeyboardReader::setKeyboardHandler(keyhandler);
-
- /* Start keyboard handler loop */
- KeyboardReader::startLoop();
-
- finish(0);
- return 0;
+ finish(0);
+ return 0;
}
-
-
-void finish(const int signum)
-{
- /* If text window is still existing, destroy it */
-
- /* End ncurses library */
- endwin();
-
- /* Do your non-curses wrapup here */
-
+void finish(const int signum) {
+ gui->finalize();
}
+static void keyhandler(const int key) {
+ if (key == KEY_ESCAPE) {
+ // Stop keyboard handler loop
+ KeyboardReader::stop();
+ finish(0);
+ }
+ if (key == KEY_RESIZE) {
+ endwin();
+ curs_set(0); /* Hide the cursor */
-static void keyhandler(const int key)
-{
- if (key == KEY_ESCAPE) {
- // Stop keyboard handler loop
- KeyboardReader::stop();
- finish(0);
- }
+ clear();
+ refresh();
+ }
- if (key == KEY_RESIZE) {
- endwin();
- curs_set(0); /* Hide the cursor */
+ if (key == KEY_UP) {
+ cout << "KEY_UP" << endl;
+ }
- clear();
- refresh();
- }
+ if (key == KEY_DOWN) {
+ cout << "KEY_DOWN" << endl;
+ }
- if (key == KEY_DOWN) {
- cout << "KEY_DOWN" << endl;
- }
+ if (key == KEY_LEFT) {
+ cout << "KEY_LEFT" << endl;
+ }
- if (key == KEY_LEFT) {
- cout << "KEY_LEFT" << endl;
- }
+ if (key == KEY_RIGHT) {
+ cout << "KEY_RIGHT" << endl;
+ }
- if (key == KEY_RIGHT) {
- cout << "KEY_RIGHT" << endl;
- }
+ if (key == 'm') {
+ //gui->getTextWindow->displayString("Message displayed");
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sch...@us...> - 2008-12-22 23:22:32
|
Revision: 61
http://deraciel.svn.sourceforge.net/deraciel/?rev=61&view=rev
Author: schnippi001
Date: 2008-12-22 22:09:46 +0000 (Mon, 22 Dec 2008)
Log Message:
-----------
Last checkin failed, this will fix the build
Added Paths:
-----------
trunk/CMakeLists.txt
trunk/GUI.h
trunk/KeyboardReader.cpp
trunk/KeyboardReader.h
trunk/Map.h
trunk/MapWindow.h
trunk/NCursesGUI.cpp
trunk/NCursesGUI.h
trunk/NCursesMapWindow.cpp
trunk/NCursesMapWindow.h
trunk/NCursesStatusWindow.cpp
trunk/NCursesStatusWindow.h
trunk/NCursesTextWindow.cpp
trunk/NCursesTextWindow.h
trunk/StatusWindow.h
trunk/TextWindow.h
trunk/_cmake-distclean.bash
trunk/main.cpp
Removed Paths:
-------------
trunk/CMakeLists.txt
trunk/_cmake-distclean.bash
trunk/char.h
trunk/cpp/
trunk/inventory.c
trunk/inventory.h
trunk/keyboard.c
trunk/keyboard.h
trunk/main.c
trunk/map_window.c
trunk/map_window.h
trunk/obj_types.c
trunk/obj_types.h
trunk/object.c
trunk/object.h
trunk/random.c
trunk/random.h
trunk/stat.h
trunk/status_window.c
trunk/status_window.h
trunk/text_window.c
trunk/text_window.h
trunk/util.h
Deleted: trunk/CMakeLists.txt
===================================================================
--- trunk/CMakeLists.txt 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/CMakeLists.txt 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,26 +0,0 @@
-cmake_minimum_required(VERSION 2.6)
-
-project(deraciel)
-SET(CMAKE_C_FLAGS "-Wall -Werror -std=c99")
-
-# requirements
-find_library( NCURSES_LIBRARY ncurses )
-if( NCURSES_LIBRARY )
- message( STATUS "ncurses library found: ${NCURSES_LIBRARY}" )
-else( NCURSES_LIBRARY )
- message( FATAL_ERROR "ncurses library not found". )
-endif( NCURSES_LIBRARY )
-
-include_directories(
- ${NCURSES_INCLUDE_DIRS}
-)
-link_directories(
- ${NCURSES_LIBRARY_DIRS}
-)
-
-# build
-file(GLOB DERACIEL_SOURCES *.c)
-add_executable(deraciel ${DERACIEL_SOURCES})
-target_link_libraries(deraciel
- ${NCURSES_LIBRARY}
-)
Copied: trunk/CMakeLists.txt (from rev 59, trunk/cpp/CMakeLists.txt)
===================================================================
--- trunk/CMakeLists.txt (rev 0)
+++ trunk/CMakeLists.txt 2008-12-22 22:09:46 UTC (rev 61)
@@ -0,0 +1,26 @@
+cmake_minimum_required(VERSION 2.6)
+
+project(deraciel)
+SET(CMAKE_CXX_FLAGS "-Wall -Werror -g")
+
+# requirements
+find_library( NCURSES_LIBRARY ncurses )
+if( NCURSES_LIBRARY )
+ message( STATUS "ncurses library found: ${NCURSES_LIBRARY}" )
+else( NCURSES_LIBRARY )
+ message( FATAL_ERROR "ncurses library not found". )
+endif( NCURSES_LIBRARY )
+
+include_directories(
+ ${NCURSES_INCLUDE_DIRS}
+)
+link_directories(
+ ${NCURSES_LIBRARY_DIRS}
+)
+
+# build
+file(GLOB DERACIEL_SOURCES *.cpp)
+add_executable(deraciel ${DERACIEL_SOURCES})
+target_link_libraries(deraciel
+ ${NCURSES_LIBRARY}
+)
Added: trunk/GUI.h
===================================================================
--- trunk/GUI.h (rev 0)
+++ trunk/GUI.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -0,0 +1,26 @@
+/*
+ * File: GUI.h
+ * Author: schnippi
+ *
+ * Created on 22. Dezember 2008, 22:50
+ */
+
+#ifndef _GUI_H
+#define _GUI_H
+
+#include "TextWindow.h"
+#include "MapWindow.h"
+#include "StatusWindow.h"
+
+class GUI {
+public:
+ virtual void initialize() = 0;
+ virtual void finalize() = 0;
+ virtual TextWindow *getTextWindow() = 0;
+ virtual MapWindow *getMapWindow() = 0;
+ virtual StatusWindow *getStatusWindow() = 0;
+};
+
+
+#endif /* _GUI_H */
+
Property changes on: trunk/GUI.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Copied: trunk/KeyboardReader.cpp (from rev 59, trunk/cpp/KeyboardReader.cpp)
===================================================================
--- trunk/KeyboardReader.cpp (rev 0)
+++ trunk/KeyboardReader.cpp 2008-12-22 22:09:46 UTC (rev 61)
@@ -0,0 +1,48 @@
+#include "KeyboardReader.h"
+
+#include <iostream>
+#include <ncurses.h>
+
+
+using namespace std;
+
+
+
+bool KeyboardReader::keyboardReaderActive = true;
+void (*KeyboardReader::keyboardHandler)(const int key) = NULL;
+
+void KeyboardReader::setKeyboardHandler(void (*handler)(const int key)) {
+ /* If the specified keyboard handler is not NULL set it as active keyboard handling function */
+ if (handler) {
+ keyboardHandler = handler;
+ } else {
+ cerr << "ERROR: Specified keyboard handler was NULL!" << endl;
+ }
+}
+
+
+
+void KeyboardReader::startLoop() {
+ /* This variable will hold the keycode of pressed key */
+ int key;
+
+ /* Run an infinite loop */
+ while(keyboardReaderActive) {
+ /* Fetch a key from keyboard buffer */
+ key = getch();
+
+ /* If handler callback is specified, delegate the previously
+ fetched key to it, else throw an error message */
+ if (keyboardHandler) {
+ keyboardHandler(key);
+ } else {
+ cerr << "ERROR: Handler callback was NULL!" << endl;
+ }
+ }
+}
+
+
+
+void KeyboardReader::stop() {
+ keyboardReaderActive = false;
+}
Property changes on: trunk/KeyboardReader.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Copied: trunk/KeyboardReader.h (from rev 59, trunk/cpp/KeyboardReader.h)
===================================================================
--- trunk/KeyboardReader.h (rev 0)
+++ trunk/KeyboardReader.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -0,0 +1,11 @@
+
+class KeyboardReader {
+public:
+ static void setKeyboardHandler(void (*handler)(const int key));
+ static void startLoop();
+ static void stop();
+
+private:
+ static void (*keyboardHandler)(const int key);
+ static bool keyboardReaderActive;
+};
\ No newline at end of file
Property changes on: trunk/KeyboardReader.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Added: trunk/Map.h
===================================================================
--- trunk/Map.h (rev 0)
+++ trunk/Map.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -0,0 +1,16 @@
+/*
+ * File: Map.h
+ * Author: schnippi
+ *
+ * Created on 22. Dezember 2008, 22:48
+ */
+
+#ifndef _MAP_H
+#define _MAP_H
+
+class Map {
+
+};
+
+#endif /* _MAP_H */
+
Property changes on: trunk/Map.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Copied: trunk/MapWindow.h (from rev 59, trunk/cpp/MapWindow.h)
===================================================================
--- trunk/MapWindow.h (rev 0)
+++ trunk/MapWindow.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -0,0 +1,20 @@
+/*
+ * File: MapWindow.h
+ * Author: schnippi
+ *
+ * Created on 22. Dezember 2008, 20:47
+ */
+
+#ifndef _MAPWINDOW_H
+#define _MAPWINDOW_H
+
+#include "Map.h"
+
+class MapWindow {
+public:
+ virtual void resize() = 0;
+ virtual void displayMap(const Map *map) = 0;
+};
+
+#endif /* _MAPWINDOW_H */
+
Property changes on: trunk/MapWindow.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Added: trunk/NCursesGUI.cpp
===================================================================
--- trunk/NCursesGUI.cpp (rev 0)
+++ trunk/NCursesGUI.cpp 2008-12-22 22:09:46 UTC (rev 61)
@@ -0,0 +1,48 @@
+#include "NCursesGUI.h"
+#include <ncurses.h>
+#include "NCursesTextWindow.h"
+#include "NCursesMapWindow.h"
+#include "NCursesStatusWindow.h"
+
+void NCursesGUI::initialize() {
+ initscr(); /* initialize the curses library */
+ keypad(stdscr, TRUE); /* enable keyboard mapping */
+ nonl(); /* tell curses not to do NL->CR/NL on output */
+ //cbreak(); /* take input chars one at a time, no wait for \n */
+ noecho(); /* don't echo input */
+
+ curs_set(0); /* Hide the cursor */
+
+ start_color();
+ init_pair(1, COLOR_WHITE, COLOR_BLUE);
+ init_pair(2, COLOR_BLACK, COLOR_YELLOW);
+ init_pair(3, COLOR_WHITE, COLOR_RED);
+ init_pair(4, COLOR_WHITE, COLOR_GREEN);
+
+ clear();
+ refresh();
+
+ textWindow = new NCursesTextWindow();
+ mapWindow = new NCursesMapWindow();
+ statusWindow = new NCursesStatusWindow();
+}
+
+void NCursesGUI::finalize() {
+ delete textWindow;
+ delete mapWindow;
+ delete statusWindow;
+
+ endwin();
+}
+
+TextWindow *NCursesGUI::getTextWindow() {
+ return textWindow;
+}
+
+MapWindow *NCursesGUI::getMapWindow() {
+ return mapWindow;
+}
+
+StatusWindow *NCursesGUI::getStatusWindow() {
+ return statusWindow;
+}
Property changes on: trunk/NCursesGUI.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/NCursesGUI.h
===================================================================
--- trunk/NCursesGUI.h (rev 0)
+++ trunk/NCursesGUI.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -0,0 +1,27 @@
+/*
+ * File: NCursesGUI.h
+ * Author: schnippi
+ *
+ * Created on 22. Dezember 2008, 22:48
+ */
+
+#ifndef _NCURSESGUI_H
+#define _NCURSESGUI_H
+
+#include "GUI.h"
+
+class NCursesGUI : public GUI {
+public:
+ void initialize();
+ void finalize();
+ TextWindow *getTextWindow();
+ MapWindow *getMapWindow();
+ StatusWindow *getStatusWindow();
+
+private:
+ TextWindow *textWindow;
+ MapWindow *mapWindow;
+ StatusWindow *statusWindow;
+};
+
+#endif /* _NCURSESGUI_H */
Property changes on: trunk/NCursesGUI.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Copied: trunk/NCursesMapWindow.cpp (from rev 59, trunk/cpp/NCursesMapWindow.cpp)
===================================================================
--- trunk/NCursesMapWindow.cpp (rev 0)
+++ trunk/NCursesMapWindow.cpp 2008-12-22 22:09:46 UTC (rev 61)
@@ -0,0 +1,38 @@
+#include "NCursesMapWindow.h"
+
+#include <iostream>
+#include <string>
+#include <ncurses.h>
+
+using namespace std;
+
+NCursesMapWindow::NCursesMapWindow() {
+ window = newwin(maxHeight, maxWidth, 2, 0);
+
+ if (!window) {
+ cerr << "Error: Map window creation failed!" << endl;
+ return;
+ }
+
+ wattron(window, COLOR_PAIR(4));
+ wbkgd(window, COLOR_PAIR(4));
+
+ wrefresh(window);
+}
+
+NCursesMapWindow::~NCursesMapWindow() {
+ /* Free resources consumed by windows */
+ delwin(window);
+}
+
+void NCursesMapWindow::resize() {
+ /* Reallocate storage for resized text window */
+ wresize(window, maxHeight, maxWidth);
+}
+
+void NCursesMapWindow::displayMap(const Map *map) {
+ /* Set cursor to first position (upper left) in map window */
+ wmove(window, 0, 0);
+
+ wnoutrefresh(window);
+}
Copied: trunk/NCursesMapWindow.h (from rev 59, trunk/cpp/NCursesMapWindow.h)
===================================================================
--- trunk/NCursesMapWindow.h (rev 0)
+++ trunk/NCursesMapWindow.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -0,0 +1,18 @@
+#include <string>
+#include <ncurses.h>
+
+#include "MapWindow.h"
+
+class NCursesMapWindow : public MapWindow {
+public:
+ NCursesMapWindow();
+ ~NCursesMapWindow();
+ void resize();
+ void displayMap(const Map *map);
+
+private:
+ WINDOW *window; // Window handle
+ static const unsigned int maxWidth = 80; // Maximum window width
+ static const unsigned int maxHeight = 20; // Maximum window height
+ static const unsigned int screensize = maxWidth * maxHeight;
+};
Copied: trunk/NCursesStatusWindow.cpp (from rev 59, trunk/cpp/NCursesStatusWindow.cpp)
===================================================================
--- trunk/NCursesStatusWindow.cpp (rev 0)
+++ trunk/NCursesStatusWindow.cpp 2008-12-22 22:09:46 UTC (rev 61)
@@ -0,0 +1,59 @@
+#include "NCursesStatusWindow.h"
+
+#include <iostream>
+#include <string>
+#include <ncurses.h>
+
+using namespace std;
+
+NCursesStatusWindow::NCursesStatusWindow() {
+ window = newwin(maxHeight, maxWidth, 25 - maxHeight, 0);
+
+ if (!window) {
+ cerr << "Error: Status window creation failed!" << endl;
+ return;
+ }
+
+ wattron(window, COLOR_PAIR(3));
+ wbkgd(window, COLOR_PAIR(3));
+
+ if (borderIsDrawn) {
+ /* Redraw border with new dimensions */
+ drawBorder();
+ }
+
+ wrefresh(window);
+}
+
+NCursesStatusWindow::~NCursesStatusWindow() {
+ /* Free resources consumed by window */
+ delwin(window);
+}
+
+void NCursesStatusWindow::resize() {
+ /* Reallocate storage for resized text window */
+ wresize(window, maxHeight, maxWidth);
+}
+
+void NCursesStatusWindow::displayStatus() {
+ if (borderIsDrawn) {
+ /* Redraw border */
+ drawBorder();
+ }
+
+ mvwprintw(window, 1, 2, "$:%d HP:%d(%d) MP:%d(%d) St:%2d Dx:%2d Co:%2d Wi:%2d Wp:%2d Ch:%2d",
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+
+ mvwprintw(window, 2, 2, "%s Xp:%2d/%d T:%d S:%d",
+ "Deraciel", 0, 1, 2, 3);
+
+ wnoutrefresh(window);
+}
+
+/*
+ Private member function declarations
+ */
+
+void NCursesStatusWindow::drawBorder() {
+ wborder(window, 0, 0, 0, ' ', '/', '\\', ACS_VLINE, ACS_VLINE);
+}
Copied: trunk/NCursesStatusWindow.h (from rev 59, trunk/cpp/NCursesStatusWindow.h)
===================================================================
--- trunk/NCursesStatusWindow.h (rev 0)
+++ trunk/NCursesStatusWindow.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -0,0 +1,19 @@
+#include <string>
+#include <ncurses.h>
+
+#include "StatusWindow.h"
+
+class NCursesStatusWindow : public StatusWindow {
+public:
+ NCursesStatusWindow();
+ ~NCursesStatusWindow();
+ void resize();
+ void displayStatus();
+
+private:
+ WINDOW *window; // Window handle
+ static const unsigned int maxWidth = 80; // Maximum window width
+ static const unsigned int maxHeight = 3; // Maximum window height
+ static const bool borderIsDrawn = true; // Draw window borders by default
+ void drawBorder();
+};
\ No newline at end of file
Copied: trunk/NCursesTextWindow.cpp (from rev 59, trunk/cpp/NCursesTextWindow.cpp)
===================================================================
--- trunk/NCursesTextWindow.cpp (rev 0)
+++ trunk/NCursesTextWindow.cpp 2008-12-22 22:09:46 UTC (rev 61)
@@ -0,0 +1,68 @@
+#include "NCursesTextWindow.h"
+
+#include <iostream>
+#include <string>
+#include <ncurses.h>
+
+using namespace std;
+
+NCursesTextWindow::NCursesTextWindow() {
+ borderWindow = newwin(maxHeight, maxWidth, 0, 0);
+ textWindow = newwin(maxHeight - 1, maxWidth - 2, 0, 1);
+
+ if (!borderWindow || !textWindow) {
+ cerr << "Error: Text window creation failed!" << endl;
+ return;
+ }
+
+ wattron(borderWindow, COLOR_PAIR(1));
+ wbkgd(textWindow, COLOR_PAIR(1));
+
+ if (borderIsDrawn) {
+ /* Redraw border with new dimensions */
+ drawBorder();
+ }
+
+ wrefresh(borderWindow);
+ wrefresh(textWindow);
+}
+
+NCursesTextWindow::~NCursesTextWindow() {
+ /* Free resources consumed by windows */
+ delwin(borderWindow);
+ delwin(textWindow);
+}
+
+void NCursesTextWindow::resize() {
+ /* Reallocate storage for resized text window */
+ wresize(borderWindow, maxHeight, maxWidth);
+ wresize(textWindow, maxHeight - 1, maxWidth);
+}
+
+void NCursesTextWindow::clear() {
+ if (borderIsDrawn) {
+ /* Redraw border with new dimensions */
+ drawBorder();
+ }
+}
+
+void NCursesTextWindow::displayString(const string string) {
+ if (borderIsDrawn) {
+ /* Redraw border*/
+ drawBorder();
+ }
+
+ wmove(textWindow, 0, 0);
+ wprintw(textWindow, string.c_str());
+
+ wnoutrefresh(borderWindow);
+ wnoutrefresh(textWindow);
+}
+
+/*
+ Private member function declarations
+ */
+
+void NCursesTextWindow::drawBorder() {
+ wborder(borderWindow, 0, 0, ' ', 0, ACS_VLINE, ACS_VLINE, '\\', '/');
+}
\ No newline at end of file
Copied: trunk/NCursesTextWindow.h (from rev 59, trunk/cpp/NCursesTextWindow.h)
===================================================================
--- trunk/NCursesTextWindow.h (rev 0)
+++ trunk/NCursesTextWindow.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -0,0 +1,21 @@
+#include <string>
+#include <ncurses.h>
+
+#include "TextWindow.h"
+
+class NCursesTextWindow : public TextWindow {
+public:
+ NCursesTextWindow();
+ ~NCursesTextWindow();
+ void resize();
+ void clear();
+ void displayString(const std::string string);
+
+private:
+ WINDOW *borderWindow; // Window handle
+ WINDOW *textWindow; // Window handle
+ static const unsigned int maxWidth = 80; // Maximum window width
+ static const unsigned int maxHeight = 2; // Maximum window height
+ static const bool borderIsDrawn = true; // Draw window borders by default
+ void drawBorder();
+};
Copied: trunk/StatusWindow.h (from rev 59, trunk/cpp/StatusWindow.h)
===================================================================
--- trunk/StatusWindow.h (rev 0)
+++ trunk/StatusWindow.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -0,0 +1,19 @@
+/*
+ * File: StatusWindow.h
+ * Author: schnippi
+ *
+ * Created on 22. Dezember 2008, 20:47
+ */
+
+#ifndef _STATUSWINDOW_H
+#define _STATUSWINDOW_H
+
+class StatusWindow {
+public:
+ virtual void resize() = 0;
+ virtual void displayStatus() = 0;
+};
+
+
+#endif /* _STATUSWINDOW_H */
+
Property changes on: trunk/StatusWindow.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Copied: trunk/TextWindow.h (from rev 59, trunk/cpp/TextWindow.h)
===================================================================
--- trunk/TextWindow.h (rev 0)
+++ trunk/TextWindow.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -0,0 +1,21 @@
+/*
+ * File: TextWindow.h
+ * Author: schnippi
+ *
+ * Created on 22. Dezember 2008, 04:28
+ */
+
+#ifndef _DERACIEL_TEXTWINDOW_H
+#define _DERACIEL_TEXTWINDOW_H
+
+#include <string>
+
+class TextWindow {
+public:
+ virtual void resize() = 0;
+ virtual void clear() = 0;
+ virtual void displayString(const std::string string) = 0;
+};
+
+
+#endif /* _DERACIEL_TEXTWINDOW_H */
Property changes on: trunk/TextWindow.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Deleted: trunk/_cmake-distclean.bash
===================================================================
--- trunk/_cmake-distclean.bash 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/_cmake-distclean.bash 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,27 +0,0 @@
-#!/bin/bash
-find . -name "*.cmake" |while read f; do
- echo "rm ${f}"
- rm "${f}"
-done
-
-find . -name "CMakeCache.txt" |while read f; do
- echo "rm ${f}"
- rm "${f}"
-done
-
-find . -name "Makefile" |while read f; do
- echo "rm ${f}"
- rm "${f}"
-done
-
-find . -type d -name CMakeFiles |while read d; do
- echo "rm -r ${d}"
- rm -r "${d}"
-done
-
-find . -type d -name CMakeTmp |while read d; do
- echo "rm -r ${d}"
- rm -r "${d}"
-done
-
-
Copied: trunk/_cmake-distclean.bash (from rev 59, trunk/cpp/_cmake-distclean.bash)
===================================================================
--- trunk/_cmake-distclean.bash (rev 0)
+++ trunk/_cmake-distclean.bash 2008-12-22 22:09:46 UTC (rev 61)
@@ -0,0 +1,27 @@
+#!/bin/bash
+find . -name "*.cmake" |while read f; do
+ echo "rm ${f}"
+ rm "${f}"
+done
+
+find . -name "CMakeCache.txt" |while read f; do
+ echo "rm ${f}"
+ rm "${f}"
+done
+
+find . -name "Makefile" |while read f; do
+ echo "rm ${f}"
+ rm "${f}"
+done
+
+find . -type d -name CMakeFiles |while read d; do
+ echo "rm -r ${d}"
+ rm -r "${d}"
+done
+
+find . -type d -name CMakeTmp |while read d; do
+ echo "rm -r ${d}"
+ rm -r "${d}"
+done
+
+
Deleted: trunk/char.h
===================================================================
--- trunk/char.h 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/char.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,31 +0,0 @@
-#ifndef DERACIEL_CHAR_H
-#define DERACIEL_CHAR_H
-
-#include <stdint.h>
-
-#include "inventory.h"
-#include "stat.h"
-
-struct char_struct
-{
- char name[32];
-
- stat_t stats[STAT_MAX_STATS];
-
- uint32_t experience;
- uint8_t level;
-
- uint32_t turns;
- uint32_t score;
-
- int16_t cur_hitpoints;
- int16_t max_hitpoints;
-
- int16_t cur_magic;
- int16_t max_magic;
-
- struct invt_struct inventory;
-};
-
-#endif // !DERACIEL_CHAR_H
-
Deleted: trunk/inventory.c
===================================================================
--- trunk/inventory.c 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/inventory.c 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,16 +0,0 @@
-#include "inventory.h"
-
-void invt_init(struct invt_struct *inventory)
-{
- memset(inventory, 0, sizeof(struct invt_struct));
-
- inventory->coins = obj_init(OBJ_DESC_COINS);
-}
-
-void invt_uninit(struct invt_struct *inventory) {
- obj_uninit(inventory->coins);
-
- for (int i = 0; i < MAX_INVENTORY_OBJECTS; ++i)
- obj_uninit(inventory->objects[i]);
-}
-
Deleted: trunk/inventory.h
===================================================================
--- trunk/inventory.h 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/inventory.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,19 +0,0 @@
-#ifndef DERACIEL_INVENTORY_H
-#define DERACIEL_INVENTORY_H
-
-#include "object.h"
-
-#define MAX_INVENTORY_OBJECTS 26
-
-struct invt_struct
-{
- struct obj_struct *coins;
-
- struct obj_struct *objects[MAX_INVENTORY_OBJECTS];
-};
-
-void invt_init(struct invt_struct *inventory);
-
-void invt_uninit(struct invt_struct *inventory);
-
-#endif
Deleted: trunk/keyboard.c
===================================================================
--- trunk/keyboard.c 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/keyboard.c 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,64 +0,0 @@
-#include "keyboard.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <ncurses.h>
-
-#include "util.h"
-
-static void (*handler_cb)(const int key);
-static bool keyreader_is_active = false;
-/*
- The keyreader is an infinite loop that gets one character at iteration and
- passes it to a keyboard handling callback. The callback then can respond
- appropriately to the given key. This function is running inside a thread
- created by keyreader_create().
-*/
-static void keyreader()
-{
- /* This variable will hold the keycode of pressed key */
- int key;
-
- /* Run an infinite loop */
- while(keyreader_is_active) {
- /* Fetch a key from keyboard buffer */
- key = getch();
-
- /* If handler callback is specified, delegate the previously
- fetched key to it, else throw an error message */
- if (handler_cb) {
- handler_cb(key);
- } else {
- fprintf(stderr, "ERROR: Handler callback was NULL!\n");
- }
- }
-}
-
-
-/*
- Creates a thread that runs keyreader().
-*/
-void keyreader_start()
-{
- keyreader_is_active = true;
- keyreader();
-}
-
-
-
-void keyreader_stop()
-{
- keyreader_is_active = false;
-}
-
-
-
-void keyreader_set_handler(void(*cb)(const int key))
-{
- /* If the callback is not NULL set it as active keyboard handling function */
- if (cb) {
- handler_cb = cb;
- } else {
- fprintf(stderr, "ERROR: Specified callback was NULL!\n");
- }
-}
Deleted: trunk/keyboard.h
===================================================================
--- trunk/keyboard.h 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/keyboard.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,10 +0,0 @@
-#ifndef DERACIEL_KEYBOARD_H
-#define DERACIEL_KEYBOARD_H
-
-#include <stdint.h>
-
-void keyreader_start(void);
-void keyreader_stop(void);
-void keyreader_set_handler(void(*cb)(const int key));
-
-#endif // !DERACIEL_KEYBOARD_H
Deleted: trunk/main.c
===================================================================
--- trunk/main.c 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/main.c 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,146 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <signal.h>
-#include <time.h>
-#include <unistd.h>
-#include <ncurses.h>
-
-#include "text_window.h"
-#include "status_window.h"
-#include "map_window.h"
-#include "random.h"
-#include "keyboard.h"
-
-
-#define KEY_ESCAPE 27
-
-static void finish(const int);
-static void test_keyhandler(const int key);
-
-static struct char_struct main_char =
-{
- "Foobar the Apprentice",
- { 16, 16, 16, 16, 16, 16 },
- 0,
- 1,
- 0,
- 0,
- 16,
- 16,
- 10,
- 10,
- { 0 }
-};
-
-int main(int argc, char **argv)
-{
- signal(SIGINT, finish); /* arrange interrupts to terminate */
- initscr(); /* initialize the curses library */
- keypad(stdscr, TRUE); /* enable keyboard mapping */
- nonl(); /* tell curses not to do NL->CR/NL on output */
- //cbreak(); /* take input chars one at a time, no wait for \n */
- noecho(); /* don't echo input */
-
- curs_set(0); /* Hide the cursor */
-
- start_color();
- init_pair(1, COLOR_WHITE, COLOR_BLUE);
- init_pair(2, COLOR_BLACK, COLOR_YELLOW);
- init_pair(3, COLOR_WHITE, COLOR_RED);
- init_pair(4, COLOR_WHITE, COLOR_GREEN);
-
- clear();
- refresh();
-
- text_window_create();
- map_window_create();
- status_window_create();
-
- invt_init(&main_char.inventory);
-
- /* Assign keyboard handler callback */
- keyreader_set_handler(test_keyhandler);
-
- /* Start keyboard reader */
- keyreader_start();
-
- /* Let thread work */
- while(1) { sleep(5); };
-
- invt_uninit(&main_char.inventory);
-
- finish(0);
- return 0;
-}
-
-
-
-void finish(const int signum)
-{
- /* If text window is still existing, destroy it */
- text_window_destroy();
- map_window_destroy();
- status_window_destroy();
-
- /* End ncurses library */
- endwin();
-
- /* do your non-curses wrapup here */
-
- exit(0);
-}
-
-static int counter = 0;
-static chtype map[80*20];
-
-static void test_keyhandler(const int key)
-{
- text_window_clear();
-
- if (key == KEY_ESCAPE) finish(0);
-
- if (key == KEY_RESIZE) {
- endwin();
- curs_set(0); /* Hide the cursor */
-
- text_window_resize();
- map_window_resize();
- status_window_resize();
- clear();
- refresh();
- }
-
- if (key == KEY_DOWN) {
- counter++;
- if (counter == 1) {
- text_window_display_string("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
- }
-
- if (counter == 2) {
- text_window_display_string("Ein etwas laengerer Text 2");
- }
-
- if (counter == 3) {
- text_window_display_string("Und Text 3");
- counter = 0;
- }
- }
-
- if (key == KEY_LEFT) {
- for (int i = 0; i < 80*20; i++) {
- map[i] = 'o';
- }
- map_window_display_map(map);
- }
-
- if (key == KEY_RIGHT) {
- for (int i = 0; i < 80*20; i++) {
- map[i] = '*';
- }
- map_window_display_map(map);
- }
-
- status_window_update(&main_char);
-
- doupdate();
-}
Copied: trunk/main.cpp (from rev 59, trunk/cpp/main.cpp)
===================================================================
--- trunk/main.cpp (rev 0)
+++ trunk/main.cpp 2008-12-22 22:09:46 UTC (rev 61)
@@ -0,0 +1,73 @@
+#include <iostream>
+#include <signal.h>
+#include <ncurses.h>
+
+#include "NCursesGUI.h"
+#include "KeyboardReader.h"
+
+using namespace std;
+
+#define KEY_ESCAPE 27
+
+static void finish(const int signum);
+static void keyhandler(const int key);
+
+GUI *gui;
+
+int main(int argc, char **argv) {
+ signal(SIGINT, finish); /* arrange interrupts to terminate */
+
+ gui = new NCursesGUI();
+ gui->initialize();
+
+ //gui->getStatusWindow->displayStatus();
+
+ /* Assign key handler callback */
+ KeyboardReader::setKeyboardHandler(keyhandler);
+
+ /* Start keyboard handler loop */
+ KeyboardReader::startLoop();
+
+ finish(0);
+ return 0;
+}
+
+void finish(const int signum) {
+ gui->finalize();
+}
+
+static void keyhandler(const int key) {
+ if (key == KEY_ESCAPE) {
+ // Stop keyboard handler loop
+ KeyboardReader::stop();
+ finish(0);
+ }
+
+ if (key == KEY_RESIZE) {
+ endwin();
+ curs_set(0); /* Hide the cursor */
+
+ clear();
+ refresh();
+ }
+
+ if (key == KEY_UP) {
+ cout << "KEY_UP" << endl;
+ }
+
+ if (key == KEY_DOWN) {
+ cout << "KEY_DOWN" << endl;
+ }
+
+ if (key == KEY_LEFT) {
+ cout << "KEY_LEFT" << endl;
+ }
+
+ if (key == KEY_RIGHT) {
+ cout << "KEY_RIGHT" << endl;
+ }
+
+ if (key == 'm') {
+ //gui->getTextWindow->displayString("Message displayed");
+ }
+}
Property changes on: trunk/main.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Deleted: trunk/map_window.c
===================================================================
--- trunk/map_window.c 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/map_window.c 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,61 +0,0 @@
-#include "map_window.h"
-
-#include <string.h>
-#include <ncurses.h>
-
-#define MAPWINDOW_MAXWIDTH (80)
-#define MAPWINDOW_MAXHEIGHT (20)
-#define MAPWINDOW_SCREENSIZE (MAPWINDOW_MAXWIDTH * MAPWINDOW_MAXHEIGHT)
-
-static WINDOW *map_wnd; /* Window handle */
-
-
-
-void map_window_create(void)
-{
- map_wnd = newwin(MAPWINDOW_MAXHEIGHT, MAPWINDOW_MAXWIDTH, 2, 0);
-
- if (!map_wnd) {
- fprintf(stderr, "map window creation failed!\n");
- return;
- }
-
- wattron(map_wnd, COLOR_PAIR(4));
- wbkgd(map_wnd, COLOR_PAIR(4));
-
- wrefresh(map_wnd);
-}
-
-
-
-void map_window_destroy()
-{
- if (map_wnd) {
- /* Free resources consumed by the window */
- delwin(map_wnd);
- map_wnd = NULL;
- }
-}
-
-
-
-void map_window_resize(void)
-{
- /* Reallocate storage for resized text window */
- wresize(map_wnd, MAPWINDOW_MAXHEIGHT, MAPWINDOW_MAXWIDTH);
-}
-
-
-
-void map_window_display_map(const chtype *map)
-{
- /* Set cursor to first position (upper left) in map window */
- wmove(map_wnd, 0, 0);
-
- /* Copy map to local map */
- for (int s = 0; s < MAPWINDOW_SCREENSIZE; s++) {
- waddch(map_wnd, map[s]);
- }
-
- wnoutrefresh(map_wnd);
-}
Deleted: trunk/map_window.h
===================================================================
--- trunk/map_window.h 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/map_window.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,11 +0,0 @@
-#ifndef DERACIEL_MAP_WINDOW_H
-#define DERACIEL_MAP_WINDOW_H
-
-#include <ncurses.h>
-
-void map_window_create(void);
-void map_window_destroy(void);
-void map_window_resize(void);
-void map_window_display_map(const chtype *m);
-
-#endif // !DERACIEL_MAP_WINDOW_H
Deleted: trunk/obj_types.c
===================================================================
--- trunk/obj_types.c 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/obj_types.c 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,52 +0,0 @@
-#include "obj_types.h"
-#include "object.h"
-
-// Gold piles always contain 0 coins by default
-static const uint32_t coins_default_value = 0;
-
-#define DEFINE_OBJ(ID, d, s) { ID, false, d, s }
-
-static struct obj_desc_struct obj_descs[] =
-{
- DEFINE_OBJ(OBJ_DESC_COINS, &coins_default_value, sizeof(coins_default_value)),
- DEFINE_OBJ(OBJ_DESC_INVALID, NULL, 0)
-};
-
-const struct obj_desc_struct *obj_desc_find(obj_descriptor_id id)
-{
- if (id == OBJ_DESC_INVALID)
- return NULL;
-
- for (int i = 0; obj_descs[i].id != OBJ_DESC_INVALID; ++i)
- {
- if (obj_descs[i].id == id)
- return obj_descs + i;
- }
-
- return NULL;
-}
-
-bool obj_desc_is_identified(obj_descriptor_id id)
-{
- const struct obj_desc_struct *desc = obj_desc_find(id);
- if (desc)
- return desc->is_identified;
- return false;
-}
-
-void obj_desc_mark_identified(obj_descriptor_id id)
-{
- struct obj_desc_struct *desc = (struct obj_desc_struct *)obj_desc_find(id);
- if (desc)
- {
- desc->is_identified = true;
- obj_update_names(id);
- }
-}
-
-const char *obj_desc_get_name(obj_descriptor_id id)
-{
- // TODO
- return "";
-}
-
Deleted: trunk/obj_types.h
===================================================================
--- trunk/obj_types.h 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/obj_types.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,45 +0,0 @@
-#ifndef DERACIEL_OBJ_TYPES_H
-#define DERACIEL_OBJ_TYPES_H
-
-#include "util.h"
-
-#include <stdint.h>
-#include <string.h>
-
-typedef uint32_t obj_descriptor_id;
-
-#define OBJ_DESC_INVALID ((obj_descriptor_id)-1)
-
-/**
- * Different object types we have
- */
-enum
-{
- /**
- * Object type for coins.
- *
- * [default_data] = uint32_t => indicating how many gold coins there are
- */
- OBJ_DESC_COINS
-};
-
-struct obj_desc_struct
-{
- obj_descriptor_id id;
-
- bool is_identified;
-
- const void *default_data;
- size_t default_data_size;
-};
-
-const struct obj_desc_struct *obj_desc_find(obj_descriptor_id id);
-
-bool obj_desc_is_identified(obj_descriptor_id id);
-
-void obj_desc_mark_identified(obj_descriptor_id id);
-
-const char *obj_desc_get_name(obj_descriptor_id id);
-
-#endif
-
Deleted: trunk/object.c
===================================================================
--- trunk/object.c 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/object.c 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,44 +0,0 @@
-#include "object.h"
-#include "util.h"
-
-#include <string.h>
-
-struct obj_struct *obj_init(obj_descriptor_id id)
-{
- struct obj_struct *obj;
- mem_alloc(struct obj_struct, obj);
- // TODO: need to put obj into a global object list
-
- obj->id = id;
-
- strncpy(obj->name, obj_desc_get_name(id), sizeof(obj->name));
- obj->name[sizeof(obj->name)-1] = 0;
-
- memset(obj->user_name, 0, sizeof(obj->user_name));
-
- const struct obj_desc_struct *obj_desc = obj_desc_find(id);
- if (obj_desc)
- {
- mem_alloc_size(obj_desc->default_data_size, void, obj->user_data);
- memcpy(obj->user_data, obj_desc->default_data, obj_desc->default_data_size);
- }
- else
- {
- obj->user_data = NULL;
- }
-
- return obj;
-}
-
-void obj_uninit(struct obj_struct *obj)
-{
- mem_dealloc(obj->user_data);
- // TODO: remove obj from global object list
- mem_dealloc(obj);
-}
-
-void obj_update_names(obj_descriptor_id id)
-{
- // TODO: implemt via global object list
-}
-
Deleted: trunk/object.h
===================================================================
--- trunk/object.h 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/object.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,29 +0,0 @@
-#ifndef DERACIEL_OBJECT_H
-#define DERACIEL_OBJECT_H
-
-#include "obj_types.h"
-
-#include <stdint.h>
-
-#define OBJ_NAME_LENGTH 64
-
-struct obj_struct
-{
- obj_descriptor_id id;
- char name[OBJ_NAME_LENGTH];
- char user_name[OBJ_NAME_LENGTH];
-
- void *user_data;
-};
-
-struct obj_struct *obj_init(obj_descriptor_id id);
-
-void obj_uninit(struct obj_struct *obj);
-
-// id == OBJ_DESC_INVALID would update all object names
-// TODO: define if all unidentified objects would get
-// new random names then too
-void obj_update_names(obj_descriptor_id id);
-
-#endif
-
Deleted: trunk/random.c
===================================================================
--- trunk/random.c 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/random.c 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,57 +0,0 @@
-#include "random.h"
-#include "util.h"
-
-struct rng_struct {
- uint32_t seed;
-};
-
-
-
-struct rng_struct *rng_create(const uint32_t seed)
-{
- struct rng_struct *rng = NULL;
- mem_alloc(struct rng_struct, rng);
-
- rng->seed = seed;
-
- return rng;
-}
-
-
-
-void rng_destroy(struct rng_struct *rng)
-{
- mem_dealloc(rng);
-}
-
-
-
-unsigned int rng_gen(struct rng_struct *rng, const unsigned int high)
-{
- rng->seed = 0xDE2AC1E1 * (rng->seed + 1);
- rng->seed = (rng->seed >> 13) | (rng->seed << 19);
-
- return rng->seed % (high + 1);
-}
-
-
-
-unsigned int rng_gen_from_range(struct rng_struct *rng, const unsigned int low, const unsigned int high)
-{
- unsigned int length = abs(high - low);
- unsigned int num = rng_gen(rng, length);
-
- return low + num;
-}
-
-
-
-unsigned int rng_nroll(struct rng_struct *rng, const unsigned int n, const unsigned int sides)
-{
- unsigned int sum = 0;
- for (unsigned int i = 0; i < n; i++) {
- sum += rng_roll(rng, sides);
- }
-
- return sum;
-}
Deleted: trunk/random.h
===================================================================
--- trunk/random.h 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/random.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,51 +0,0 @@
-#ifndef DERACIEL_RANDOM_H
-#define DERACIEL_RANDOM_H
-
-#include <stdint.h>
-
-struct rng_struct;
-
-
-
-/**
- * Creates and initializes a random number generator
- */
-struct rng_struct *rng_create(const uint32_t seed);
-
-
-
-/**
- * Deinitializes a random number generator
- */
-void rng_destroy(struct rng_struct *rng);
-
-
-
-/**
- * Returns a number of the interval [0, high]
- */
-unsigned int rng_gen(struct rng_struct *rng, const unsigned int high);
-
-
-
-/**
- * Returns a number of the interval [low, high]
- */
-unsigned int rng_gen_from_range(struct rng_struct *rng, const unsigned int low, const unsigned int high);
-
-
-
-/**
- * Rolls a sides-sided dice n times and returns the sum
- */
-unsigned int rng_nroll(struct rng_struct *rng, const unsigned int n, const unsigned int sides);
-
-
-
-#define rng_get_bit(rng) rng_gen(rng, 1)
-
-
-
-#define rng_roll(rng, sides) rng_gen_from_range(rng, 1, sides)
-
-#endif // !DERACIEL_RANDOM_H
Deleted: trunk/stat.h
===================================================================
--- trunk/stat.h 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/stat.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,18 +0,0 @@
-#ifndef DERACIEL_STAT_H
-#define DERACIEL_STAT_H
-
-#include <stdint.h>
-
-typedef uint32_t stat_t;
-
-enum {
- STAT_STRENGTH,
- STAT_DEXTERITY,
- STAT_WISDOM,
- STAT_WILLPOWER,
- STAT_CONSTITUTION,
- STAT_CHARISMA,
- STAT_MAX_STATS
-};
-
-#endif // !DERACIEL_STAT_H
Deleted: trunk/status_window.c
===================================================================
--- trunk/status_window.c 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/status_window.c 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,80 +0,0 @@
-#include "status_window.h"
-
-#include <string.h>
-#include <ncurses.h>
-
-#define STATUSWINDOW_MAXWIDTH (80)
-#define STATUSWINDOW_MAXHEIGHT (3)
-#define STATUSWINDOW_BORDER
-
-static WINDOW *status_wnd; /* Window handle */
-
-static void draw_border();
-
-
-void status_window_create(void)
-{
- status_wnd = newwin(STATUSWINDOW_MAXHEIGHT, STATUSWINDOW_MAXWIDTH, 25-STATUSWINDOW_MAXHEIGHT, 0);
-
- if (!status_wnd) {
- fprintf(stderr, "stat window creation failed!\n");
- return;
- }
-
- wattron(status_wnd, COLOR_PAIR(3));
- wbkgd(status_wnd, COLOR_PAIR(3));
-
-#ifdef STATUSWINDOW_BORDER
- /* Redraw border with new dimensions */
- draw_border();
-#endif // !STATUSWINDOW_BORDER
-
- wrefresh(status_wnd);
-}
-
-
-
-void status_window_destroy()
-{
- if (status_wnd) {
- /* Free resources consumed by the window */
- delwin(status_wnd);
- status_wnd = NULL;
- }
-}
-
-
-
-void status_window_resize(void)
-{
- /* Reallocate storage for resized text window */
- wresize(status_wnd, STATUSWINDOW_MAXHEIGHT, STATUSWINDOW_MAXWIDTH);
-}
-
-
-
-void draw_border()
-{
- wborder(status_wnd, 0, 0, 0, ' ', '/', '\\', ACS_VLINE, ACS_VLINE);
-}
-
-
-
-void status_window_update(const struct char_struct *ch)
-{
-#ifdef STATUSWINDOW_BORDER
- /* Redraw border with new dimensions */
- draw_border();
-#endif // !STATUSWINDOW_BORDER
-
- mvwprintw(status_wnd, 1, 2, "$:%d HP:%d(%d) MP:%d(%d) St:%2d Dx:%2d Co:%2d Wi:%2d Wp:%2d Ch:%2d",
- *(uint32_t*)(ch->inventory.coins->user_data),
- ch->cur_hitpoints, ch->max_hitpoints, ch->cur_magic, ch->max_magic,
- ch->stats[STAT_STRENGTH], ch->stats[STAT_DEXTERITY], ch->stats[STAT_CONSTITUTION],
- ch->stats[STAT_WISDOM], ch->stats[STAT_WILLPOWER], ch->stats[STAT_CHARISMA]);
-
- mvwprintw(status_wnd, 2, 2, "%s Xp:%2d/%d T:%d S:%d",
- ch->name, ch->level, ch->experience, ch->turns, ch->score);
-
- wnoutrefresh(status_wnd);
-}
Deleted: trunk/status_window.h
===================================================================
--- trunk/status_window.h 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/status_window.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,12 +0,0 @@
-#ifndef DERACIEL_STATUS_WINDOW_H
-#define DERACIEL_STATUS_WINDOW_H
-
-#include "char.h"
-
-void status_window_create(void);
-void status_window_destroy(void);
-void status_window_resize(void);
-void status_window_update(const struct char_struct *ch);
-
-#endif // !DERACIEL_STATUS_WINDOW_H
-
Deleted: trunk/text_window.c
===================================================================
--- trunk/text_window.c 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/text_window.c 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,93 +0,0 @@
-#include "text_window.h"
-
-#include <string.h>
-#include <ncurses.h>
-
-#define TEXTWINDOW_MAXWIDTH (80)
-#define TEXTWINDOW_MAXHEIGHT (2)
-#define TEXTWINDOW_BORDER
-
-static WINDOW *border_wnd; /* Window handle */
-static WINDOW *text_wnd; /* Window handle */
-
-static void draw_border();
-
-
-void text_window_create(void)
-{
- border_wnd = newwin(TEXTWINDOW_MAXHEIGHT, TEXTWINDOW_MAXWIDTH, 0, 0);
- text_wnd = newwin(TEXTWINDOW_MAXHEIGHT-1, TEXTWINDOW_MAXWIDTH-2, 0, 1);
-
- if (!border_wnd || !text_wnd) {
- fprintf(stderr, "text window creation failed!\n");
- return;
- }
-
- wattron(border_wnd, COLOR_PAIR(1));
- wbkgd(text_wnd, COLOR_PAIR(1));
-
-#ifdef TEXTWINDOW_BORDER
- /* Redraw border with new dimensions */
- draw_border();
-#endif // !TEXTWINDOW_BORDER
-
- wrefresh(border_wnd);
- wrefresh(text_wnd);
-}
-
-
-
-void text_window_destroy()
-{
- if (border_wnd) {
- /* Free resources consumed by the window */
- delwin(text_wnd);
- text_wnd = NULL;
-
- delwin(border_wnd);
- border_wnd = NULL;
- }
-}
-
-
-
-void text_window_resize(void)
-{
- /* Reallocate storage for resized text window */
- wresize(border_wnd, TEXTWINDOW_MAXHEIGHT, TEXTWINDOW_MAXWIDTH);
- wresize(text_wnd, TEXTWINDOW_MAXHEIGHT-1, TEXTWINDOW_MAXWIDTH-2);
-}
-
-
-
-void text_window_display_string(const char *string)
-{
-#ifdef TEXTWINDOW_BORDER
- /* Redraw border with new dimensions */
- draw_border();
-#endif // !TEXTWINDOW_BORDER
-
- wmove(text_wnd, 0, 0);
- wprintw(text_wnd, string);
-
- wnoutrefresh(border_wnd);
- wnoutrefresh(text_wnd);
-}
-
-
-void text_window_clear()
-{
-#ifdef TEXTWINDOW_BORDER
- /* Redraw border with new dimensions */
- draw_border();
-#endif // !TEXTWINDOW_BORDER
-
- wnoutrefresh(border_wnd);
- wnoutrefresh(text_wnd);
-}
-
-
-void draw_border()
-{
- wborder(border_wnd, 0, 0, ' ', 0, ACS_VLINE, ACS_VLINE, '\\', '/');
-}
Deleted: trunk/text_window.h
===================================================================
--- trunk/text_window.h 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/text_window.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,11 +0,0 @@
-#ifndef DERACIEL_TEXT_WINDOW_H
-#define DERACIEL_TEXT_WINDOW_H
-
-void text_window_create(void);
-void text_window_destroy(void);
-void text_window_resize(void);
-void text_window_display_string(const char *string);
-void text_window_clear(void);
-
-#endif // !DERACIEL_TEXT_WINDOW_H
-
Deleted: trunk/util.h
===================================================================
--- trunk/util.h 2008-12-22 21:40:42 UTC (rev 60)
+++ trunk/util.h 2008-12-22 22:09:46 UTC (rev 61)
@@ -1,40 +0,0 @@
-#ifndef DERACIEL_UTIL_H
-#define DERACIEL_UTIL_H
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#define mem_alloc(type, var) \
- do { \
- var = (type*)malloc(sizeof(type)); \
- if (!var) { \
- fprintf(stderr, "Couldn't allocate memory for var %s of type %s in file %s line %d\n", #var, #type, __FILE__, __LINE__); \
- exit(-1); \
- } \
- } while (0)
-
-#define mem_alloc_size(size, type, var) \
- do { \
- var = (type*)malloc(size); \
- if (!var) { \
- fprintf(stderr, "Couldn't allocate memory for var %s of size %d in file %s line %d\n", #var, (int)size, __FILE__, __LINE__); \
- exit(-1); \
- } \
- } while (0)
-
-#define mem_dealloc(var) free(var)
-
-#ifndef bool
-#define bool unsigned char
-#endif // !bool
-
-#ifndef true
-#define true 1
-#endif // !true
-
-#ifndef false
-#define false 0
-#endif // !false
-
-#endif // !DERACIEL_UTIL_H
-
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sch...@us...> - 2008-12-22 23:22:17
|
Revision: 60
http://deraciel.svn.sourceforge.net/deraciel/?rev=60&view=rev
Author: schnippi001
Date: 2008-12-22 21:40:42 +0000 (Mon, 22 Dec 2008)
Log Message:
-----------
Removed branches
Removed Paths:
-------------
branches/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sch...@us...> - 2008-12-04 10:06:45
|
Revision: 58
http://deraciel.svn.sourceforge.net/deraciel/?rev=58&view=rev
Author: schnippi001
Date: 2008-12-04 10:06:31 +0000 (Thu, 04 Dec 2008)
Log Message:
-----------
Made the keyboard reader synchronized to main program flow, removing pthread dependency.
Modified Paths:
--------------
trunk/CMakeLists.txt
trunk/cpp/CMakeLists.txt
trunk/cpp/main.cpp
trunk/keyboard.c
trunk/keyboard.h
trunk/main.c
Modified: trunk/CMakeLists.txt
===================================================================
--- trunk/CMakeLists.txt 2008-11-27 20:13:02 UTC (rev 57)
+++ trunk/CMakeLists.txt 2008-12-04 10:06:31 UTC (rev 58)
@@ -23,5 +23,4 @@
add_executable(deraciel ${DERACIEL_SOURCES})
target_link_libraries(deraciel
${NCURSES_LIBRARY}
- pthread
)
Modified: trunk/cpp/CMakeLists.txt
===================================================================
--- trunk/cpp/CMakeLists.txt 2008-11-27 20:13:02 UTC (rev 57)
+++ trunk/cpp/CMakeLists.txt 2008-12-04 10:06:31 UTC (rev 58)
@@ -23,5 +23,4 @@
add_executable(deraciel ${DERACIEL_SOURCES})
target_link_libraries(deraciel
${NCURSES_LIBRARY}
- pthread
)
Modified: trunk/cpp/main.cpp
===================================================================
--- trunk/cpp/main.cpp 2008-11-27 20:13:02 UTC (rev 57)
+++ trunk/cpp/main.cpp 2008-12-04 10:06:31 UTC (rev 58)
@@ -47,9 +47,6 @@
/* Start keyboard handler loop */
KeyboardReader::startLoop();
- doupdate();
- sleep(2);
-
finish(0);
return 0;
}
Modified: trunk/keyboard.c
===================================================================
--- trunk/keyboard.c 2008-11-27 20:13:02 UTC (rev 57)
+++ trunk/keyboard.c 2008-12-04 10:06:31 UTC (rev 58)
@@ -3,25 +3,24 @@
#include <stdlib.h>
#include <stdio.h>
#include <ncurses.h>
-#include <pthread.h>
+#include "util.h"
-static pthread_t keyreader_thread;
static void (*handler_cb)(const int key);
-
+static bool keyreader_is_active = false;
/*
The keyreader is an infinite loop that gets one character at iteration and
passes it to a keyboard handling callback. The callback then can respond
appropriately to the given key. This function is running inside a thread
created by keyreader_create().
*/
-static void *keyreader(void *unused)
+static void keyreader()
{
/* This variable will hold the keycode of pressed key */
int key;
/* Run an infinite loop */
- while(1) {
+ while(keyreader_is_active) {
/* Fetch a key from keyboard buffer */
key = getch();
@@ -33,25 +32,27 @@
fprintf(stderr, "ERROR: Handler callback was NULL!\n");
}
}
-
- return NULL;
}
/*
Creates a thread that runs keyreader().
*/
-void keyreader_create()
+void keyreader_start()
{
- int rc = pthread_create(&keyreader_thread, NULL, keyreader, NULL);
- if (rc) {
- fprintf(stderr, "ERROR: Keyreader thread creation failed! (error code: %d)\n", rc);
- exit(-1);
- }
+ keyreader_is_active = true;
+ keyreader();
}
+void keyreader_stop()
+{
+ keyreader_is_active = false;
+}
+
+
+
void keyreader_set_handler(void(*cb)(const int key))
{
/* If the callback is not NULL set it as active keyboard handling function */
Modified: trunk/keyboard.h
===================================================================
--- trunk/keyboard.h 2008-11-27 20:13:02 UTC (rev 57)
+++ trunk/keyboard.h 2008-12-04 10:06:31 UTC (rev 58)
@@ -3,8 +3,8 @@
#include <stdint.h>
-void keyreader_create(void);
-
+void keyreader_start(void);
+void keyreader_stop(void);
void keyreader_set_handler(void(*cb)(const int key));
#endif // !DERACIEL_KEYBOARD_H
Modified: trunk/main.c
===================================================================
--- trunk/main.c 2008-11-27 20:13:02 UTC (rev 57)
+++ trunk/main.c 2008-12-04 10:06:31 UTC (rev 58)
@@ -58,12 +58,12 @@
invt_init(&main_char.inventory);
- /* Create keyboard handler */
- keyreader_create();
-
- /* Assign key handler callback */
+ /* Assign keyboard handler callback */
keyreader_set_handler(test_keyhandler);
+ /* Start keyboard reader */
+ keyreader_start();
+
/* Let thread work */
while(1) { sleep(5); };
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sch...@us...> - 2008-11-27 20:13:12
|
Revision: 57
http://deraciel.svn.sourceforge.net/deraciel/?rev=57&view=rev
Author: schnippi001
Date: 2008-11-27 20:13:02 +0000 (Thu, 27 Nov 2008)
Log Message:
-----------
Fixed undefined references.
Modified Paths:
--------------
trunk/cpp/KeyboardReader.cpp
Modified: trunk/cpp/KeyboardReader.cpp
===================================================================
--- trunk/cpp/KeyboardReader.cpp 2008-11-27 20:08:16 UTC (rev 56)
+++ trunk/cpp/KeyboardReader.cpp 2008-11-27 20:13:02 UTC (rev 57)
@@ -9,8 +9,8 @@
bool KeyboardReader::keyboardReaderActive = true;
+void (*KeyboardReader::keyboardHandler)(const int key) = NULL;
-
void KeyboardReader::setKeyboardHandler(void (*handler)(const int key)) {
/* If the specified keyboard handler is not NULL set it as active keyboard handling function */
if (handler) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sch...@us...> - 2008-11-27 20:08:26
|
Revision: 56
http://deraciel.svn.sourceforge.net/deraciel/?rev=56&view=rev
Author: schnippi001
Date: 2008-11-27 20:08:16 +0000 (Thu, 27 Nov 2008)
Log Message:
-----------
First C++ version checkin
Modified Paths:
--------------
trunk/main.c
trunk/map_window.c
trunk/map_window.h
trunk/text_window.c
trunk/text_window.h
Added Paths:
-----------
trunk/cpp/
trunk/cpp/CMakeLists.txt
trunk/cpp/KeyboardReader.cpp
trunk/cpp/KeyboardReader.h
trunk/cpp/MapWindow.cpp
trunk/cpp/MapWindow.h
trunk/cpp/StatusWindow.cpp
trunk/cpp/StatusWindow.h
trunk/cpp/TextWindow.cpp
trunk/cpp/TextWindow.h
trunk/cpp/_cmake-distclean.bash
trunk/cpp/main.cpp
Copied: trunk/cpp/CMakeLists.txt (from rev 54, trunk/CMakeLists.txt)
===================================================================
--- trunk/cpp/CMakeLists.txt (rev 0)
+++ trunk/cpp/CMakeLists.txt 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,27 @@
+cmake_minimum_required(VERSION 2.6)
+
+project(deraciel)
+SET(CMAKE_CXX_FLAGS "-Wall -Werror")
+
+# requirements
+find_library( NCURSES_LIBRARY ncurses )
+if( NCURSES_LIBRARY )
+ message( STATUS "ncurses library found: ${NCURSES_LIBRARY}" )
+else( NCURSES_LIBRARY )
+ message( FATAL_ERROR "ncurses library not found". )
+endif( NCURSES_LIBRARY )
+
+include_directories(
+ ${NCURSES_INCLUDE_DIRS}
+)
+link_directories(
+ ${NCURSES_LIBRARY_DIRS}
+)
+
+# build
+file(GLOB DERACIEL_SOURCES *.cpp)
+add_executable(deraciel ${DERACIEL_SOURCES})
+target_link_libraries(deraciel
+ ${NCURSES_LIBRARY}
+ pthread
+)
Property changes on: trunk/cpp/CMakeLists.txt
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Added: trunk/cpp/KeyboardReader.cpp
===================================================================
--- trunk/cpp/KeyboardReader.cpp (rev 0)
+++ trunk/cpp/KeyboardReader.cpp 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,48 @@
+#include "KeyboardReader.h"
+
+#include <iostream>
+#include <ncurses.h>
+
+
+using namespace std;
+
+
+
+bool KeyboardReader::keyboardReaderActive = true;
+
+
+void KeyboardReader::setKeyboardHandler(void (*handler)(const int key)) {
+ /* If the specified keyboard handler is not NULL set it as active keyboard handling function */
+ if (handler) {
+ keyboardHandler = handler;
+ } else {
+ cerr << "ERROR: Specified keyboard handler was NULL!" << endl;
+ }
+}
+
+
+
+void KeyboardReader::startLoop() {
+ /* This variable will hold the keycode of pressed key */
+ int key;
+
+ /* Run an infinite loop */
+ while(keyboardReaderActive) {
+ /* Fetch a key from keyboard buffer */
+ key = getch();
+
+ /* If handler callback is specified, delegate the previously
+ fetched key to it, else throw an error message */
+ if (keyboardHandler) {
+ keyboardHandler(key);
+ } else {
+ cerr << "ERROR: Handler callback was NULL!" << endl;
+ }
+ }
+}
+
+
+
+void KeyboardReader::stop() {
+ keyboardReaderActive = false;
+}
Property changes on: trunk/cpp/KeyboardReader.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/cpp/KeyboardReader.h
===================================================================
--- trunk/cpp/KeyboardReader.h (rev 0)
+++ trunk/cpp/KeyboardReader.h 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,11 @@
+
+class KeyboardReader {
+ public:
+ static void setKeyboardHandler(void (*handler)(const int key));
+ static void startLoop();
+ static void stop();
+
+ private:
+ static void (*keyboardHandler)(const int key);
+ static bool keyboardReaderActive;
+};
\ No newline at end of file
Property changes on: trunk/cpp/KeyboardReader.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/cpp/MapWindow.cpp
===================================================================
--- trunk/cpp/MapWindow.cpp (rev 0)
+++ trunk/cpp/MapWindow.cpp 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,49 @@
+#include "MapWindow.h"
+
+#include <iostream>
+#include <string>
+#include <ncurses.h>
+
+using namespace std;
+
+MapWindow::MapWindow() {
+ window = newwin(maxHeight, maxWidth, 2, 0);
+
+ if (!window) {
+ cerr << "Error: Map window creation failed!" << endl;
+ return;
+ }
+
+ wattron(window, COLOR_PAIR(4));
+ wbkgd(window, COLOR_PAIR(4));
+
+ wrefresh(window);
+}
+
+
+
+MapWindow::~MapWindow() {
+ /* Free resources consumed by windows */
+ delwin(window);
+}
+
+
+
+void MapWindow::resize() {
+ /* Reallocate storage for resized text window */
+ wresize(window, maxHeight, maxWidth);
+}
+
+
+
+void MapWindow::displayMap(const chtype *map) {
+ /* Set cursor to first position (upper left) in map window */
+ wmove(window, 0, 0);
+
+ /* Copy map to local map */
+ for (unsigned int s = 0; s < screensize; s++) {
+ waddch(window, map[s]);
+ }
+
+ wnoutrefresh(window);
+}
Property changes on: trunk/cpp/MapWindow.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/cpp/MapWindow.h
===================================================================
--- trunk/cpp/MapWindow.h (rev 0)
+++ trunk/cpp/MapWindow.h 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,17 @@
+#include <string>
+#include <ncurses.h>
+
+class MapWindow {
+ public:
+ MapWindow();
+ ~MapWindow();
+ void draw();
+ void resize();
+ void displayMap(const chtype *map);
+
+ private:
+ WINDOW *window; // Window handle
+ static const unsigned int maxWidth = 80; // Maximum window width
+ static const unsigned int maxHeight = 20; // Maximum window height
+ static const unsigned int screensize = maxWidth * maxHeight;
+};
\ No newline at end of file
Property changes on: trunk/cpp/MapWindow.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/cpp/StatusWindow.cpp
===================================================================
--- trunk/cpp/StatusWindow.cpp (rev 0)
+++ trunk/cpp/StatusWindow.cpp 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,62 @@
+#include "StatusWindow.h"
+
+#include <iostream>
+#include <string>
+#include <ncurses.h>
+
+using namespace std;
+
+StatusWindow::StatusWindow() {
+ window = newwin(maxHeight, maxWidth, 25-maxHeight, 0);
+
+ if (!window) {
+ cerr << "Error: Status window creation failed!" << endl;
+ return;
+ }
+
+ wattron(window, COLOR_PAIR(3));
+ wbkgd(window, COLOR_PAIR(3));
+
+ wrefresh(window);
+}
+
+
+
+StatusWindow::~StatusWindow() {
+ /* Free resources consumed by window */
+ delwin(window);
+}
+
+
+
+void StatusWindow::resize() {
+ /* Reallocate storage for resized text window */
+ wresize(window, maxHeight, maxWidth);
+}
+
+
+
+void StatusWindow::displayStatus() {
+ if (borderIsDrawn) {
+ /* Redraw border */
+ drawBorder();
+ }
+
+ mvwprintw(window, 1, 2, "$:%d HP:%d(%d) MP:%d(%d) St:%2d Dx:%2d Co:%2d Wi:%2d Wp:%2d Ch:%2d",
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+
+ mvwprintw(window, 2, 2, "%s Xp:%2d/%d T:%d S:%d",
+ "Deraciel", 0, 1, 2, 3);
+
+ wnoutrefresh(window);
+}
+
+
+
+/*
+ Private member function declarations
+*/
+
+void StatusWindow::drawBorder() {
+ wborder(window, 0, 0, 0, ' ', '/', '\\', ACS_VLINE, ACS_VLINE);
+}
Property changes on: trunk/cpp/StatusWindow.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/cpp/StatusWindow.h
===================================================================
--- trunk/cpp/StatusWindow.h (rev 0)
+++ trunk/cpp/StatusWindow.h 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,17 @@
+#include <string>
+#include <ncurses.h>
+
+class StatusWindow {
+ public:
+ StatusWindow();
+ ~StatusWindow();
+ void resize();
+ void displayStatus(void);
+
+ private:
+ WINDOW *window; // Window handle
+ static const unsigned int maxWidth = 80; // Maximum window width
+ static const unsigned int maxHeight = 3; // Maximum window height
+ static const bool borderIsDrawn = true; // Draw window borders by default
+ void drawBorder();
+};
\ No newline at end of file
Property changes on: trunk/cpp/StatusWindow.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/cpp/TextWindow.cpp
===================================================================
--- trunk/cpp/TextWindow.cpp (rev 0)
+++ trunk/cpp/TextWindow.cpp 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,68 @@
+#include "TextWindow.h"
+
+#include <iostream>
+#include <string>
+#include <ncurses.h>
+
+using namespace std;
+
+TextWindow::TextWindow() {
+ borderWindow = newwin(maxHeight, maxWidth, 0, 0);
+ textWindow = newwin(maxHeight-1, maxWidth-2, 0, 1);
+
+ if (!borderWindow || !textWindow) {
+ cerr << "Error: Text window creation failed!" << endl;
+ return;
+ }
+
+ wattron(borderWindow, COLOR_PAIR(1));
+ wbkgd(textWindow, COLOR_PAIR(1));
+
+ if (borderIsDrawn) {
+ /* Redraw border with new dimensions */
+ drawBorder();
+ }
+
+ wrefresh(borderWindow);
+ wrefresh(textWindow);
+}
+
+
+
+TextWindow::~TextWindow() {
+ /* Free resources consumed by windows */
+ delwin(borderWindow);
+ delwin(textWindow);
+}
+
+
+
+void TextWindow::resize() {
+ /* Reallocate storage for resized text window */
+ wresize(borderWindow, maxHeight, maxWidth);
+ wresize(textWindow, maxHeight-1, maxWidth);
+}
+
+
+
+void TextWindow::displayString(const string string) {
+ if (borderIsDrawn) {
+ /* Redraw border*/
+ drawBorder();
+ }
+
+ wmove(textWindow, 0, 0);
+ wprintw(textWindow, string.c_str());
+
+ wnoutrefresh(borderWindow);
+ wnoutrefresh(textWindow);
+}
+
+
+/*
+ Private member function declarations
+*/
+
+void TextWindow::drawBorder() {
+ wborder(borderWindow, 0, 0, ' ', 0, ACS_VLINE, ACS_VLINE, '\\', '/');
+}
\ No newline at end of file
Property changes on: trunk/cpp/TextWindow.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/cpp/TextWindow.h
===================================================================
--- trunk/cpp/TextWindow.h (rev 0)
+++ trunk/cpp/TextWindow.h 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,19 @@
+#include <string>
+#include <ncurses.h>
+
+class TextWindow {
+ public:
+ TextWindow();
+ ~TextWindow();
+ void resize();
+ void clear();
+ void displayString(const std::string string);
+
+ private:
+ WINDOW *borderWindow; // Window handle
+ WINDOW *textWindow; // Window handle
+ static const unsigned int maxWidth = 80; // Maximum window width
+ static const unsigned int maxHeight = 2; // Maximum window height
+ static const bool borderIsDrawn = true; // Draw window borders by default
+ void drawBorder();
+};
\ No newline at end of file
Property changes on: trunk/cpp/TextWindow.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Copied: trunk/cpp/_cmake-distclean.bash (from rev 54, trunk/_cmake-distclean.bash)
===================================================================
--- trunk/cpp/_cmake-distclean.bash (rev 0)
+++ trunk/cpp/_cmake-distclean.bash 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,27 @@
+#!/bin/bash
+find . -name "*.cmake" |while read f; do
+ echo "rm ${f}"
+ rm "${f}"
+done
+
+find . -name "CMakeCache.txt" |while read f; do
+ echo "rm ${f}"
+ rm "${f}"
+done
+
+find . -name "Makefile" |while read f; do
+ echo "rm ${f}"
+ rm "${f}"
+done
+
+find . -type d -name CMakeFiles |while read d; do
+ echo "rm -r ${d}"
+ rm -r "${d}"
+done
+
+find . -type d -name CMakeTmp |while read d; do
+ echo "rm -r ${d}"
+ rm -r "${d}"
+done
+
+
Property changes on: trunk/cpp/_cmake-distclean.bash
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ text/plain
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Added: trunk/cpp/main.cpp
===================================================================
--- trunk/cpp/main.cpp (rev 0)
+++ trunk/cpp/main.cpp 2008-11-27 20:08:16 UTC (rev 56)
@@ -0,0 +1,99 @@
+#include <iostream>
+#include <signal.h>
+#include <ncurses.h>
+
+#include "TextWindow.h"
+#include "MapWindow.h"
+#include "StatusWindow.h"
+#include "KeyboardReader.h"
+
+using namespace std;
+
+#define KEY_ESCAPE 27
+
+static void finish(const int signum);
+static void keyhandler(const int key);
+
+int main(int argc, char **argv) {
+ signal(SIGINT, finish); /* arrange interrupts to terminate */
+ initscr(); /* initialize the curses library */
+ keypad(stdscr, TRUE); /* enable keyboard mapping */
+ nonl(); /* tell curses not to do NL->CR/NL on output */
+ //cbreak(); /* take input chars one at a time, no wait for \n */
+ noecho(); /* don't echo input */
+
+ curs_set(0); /* Hide the cursor */
+
+ start_color();
+ init_pair(1, COLOR_WHITE, COLOR_BLUE);
+ init_pair(2, COLOR_BLACK, COLOR_YELLOW);
+ init_pair(3, COLOR_WHITE, COLOR_RED);
+ init_pair(4, COLOR_WHITE, COLOR_GREEN);
+
+ clear();
+ refresh();
+
+ TextWindow textWindow;
+ MapWindow mapWindow;
+ StatusWindow statusWindow;
+
+ statusWindow.displayStatus();
+
+ //invt_init(&main_char.inventory);
+
+ /* Assign key handler callback */
+ KeyboardReader::setKeyboardHandler(keyhandler);
+
+ /* Start keyboard handler loop */
+ KeyboardReader::startLoop();
+
+ doupdate();
+ sleep(2);
+
+ finish(0);
+ return 0;
+}
+
+
+
+void finish(const int signum)
+{
+ /* If text window is still existing, destroy it */
+
+ /* End ncurses library */
+ endwin();
+
+ /* Do your non-curses wrapup here */
+
+}
+
+
+
+static void keyhandler(const int key)
+{
+ if (key == KEY_ESCAPE) {
+ // Stop keyboard handler loop
+ KeyboardReader::stop();
+ finish(0);
+ }
+
+ if (key == KEY_RESIZE) {
+ endwin();
+ curs_set(0); /* Hide the cursor */
+
+ clear();
+ refresh();
+ }
+
+ if (key == KEY_DOWN) {
+ cout << "KEY_DOWN" << endl;
+ }
+
+ if (key == KEY_LEFT) {
+ cout << "KEY_LEFT" << endl;
+ }
+
+ if (key == KEY_RIGHT) {
+ cout << "KEY_RIGHT" << endl;
+ }
+}
Property changes on: trunk/cpp/main.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: trunk/main.c
===================================================================
--- trunk/main.c 2008-11-24 05:32:17 UTC (rev 55)
+++ trunk/main.c 2008-11-27 20:08:16 UTC (rev 56)
@@ -113,15 +113,15 @@
if (key == KEY_DOWN) {
counter++;
if (counter == 1) {
- text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
+ text_window_display_string("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
}
if (counter == 2) {
- text_window_out("Ein etwas laengerer Text 2");
+ text_window_display_string("Ein etwas laengerer Text 2");
}
if (counter == 3) {
- text_window_out("Und Text 3");
+ text_window_display_string("Und Text 3");
counter = 0;
}
}
@@ -130,14 +130,14 @@
for (int i = 0; i < 80*20; i++) {
map[i] = 'o';
}
- map_window_update(map);
+ map_window_display_map(map);
}
if (key == KEY_RIGHT) {
for (int i = 0; i < 80*20; i++) {
map[i] = '*';
}
- map_window_update(map);
+ map_window_display_map(map);
}
status_window_update(&main_char);
Modified: trunk/map_window.c
===================================================================
--- trunk/map_window.c 2008-11-24 05:32:17 UTC (rev 55)
+++ trunk/map_window.c 2008-11-27 20:08:16 UTC (rev 56)
@@ -47,7 +47,7 @@
-void map_window_update(const chtype *map)
+void map_window_display_map(const chtype *map)
{
/* Set cursor to first position (upper left) in map window */
wmove(map_wnd, 0, 0);
Modified: trunk/map_window.h
===================================================================
--- trunk/map_window.h 2008-11-24 05:32:17 UTC (rev 55)
+++ trunk/map_window.h 2008-11-27 20:08:16 UTC (rev 56)
@@ -6,6 +6,6 @@
void map_window_create(void);
void map_window_destroy(void);
void map_window_resize(void);
-void map_window_update(const chtype *m);
+void map_window_display_map(const chtype *m);
#endif // !DERACIEL_MAP_WINDOW_H
Modified: trunk/text_window.c
===================================================================
--- trunk/text_window.c 2008-11-24 05:32:17 UTC (rev 55)
+++ trunk/text_window.c 2008-11-27 20:08:16 UTC (rev 56)
@@ -60,7 +60,7 @@
-void text_window_out(const char *string)
+void text_window_display_string(const char *string)
{
#ifdef TEXTWINDOW_BORDER
/* Redraw border with new dimensions */
Modified: trunk/text_window.h
===================================================================
--- trunk/text_window.h 2008-11-24 05:32:17 UTC (rev 55)
+++ trunk/text_window.h 2008-11-27 20:08:16 UTC (rev 56)
@@ -4,7 +4,7 @@
void text_window_create(void);
void text_window_destroy(void);
void text_window_resize(void);
-void text_window_out(const char *string);
+void text_window_display_string(const char *string);
void text_window_clear(void);
#endif // !DERACIEL_TEXT_WINDOW_H
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sch...@us...> - 2008-11-24 05:32:26
|
Revision: 55
http://deraciel.svn.sourceforge.net/deraciel/?rev=55&view=rev
Author: schnippi001
Date: 2008-11-24 05:32:17 +0000 (Mon, 24 Nov 2008)
Log Message:
-----------
Fixed a regression in which resizing the terminal caused the game windows to spread
completely over the new size instead of their fixed size
Modified Paths:
--------------
trunk/main.c
trunk/map_window.c
trunk/map_window.h
trunk/text_window.c
trunk/text_window.h
Added Paths:
-----------
trunk/status_window.c
trunk/status_window.h
Removed Paths:
-------------
trunk/stat_window.c
trunk/stat_window.h
Modified: trunk/main.c
===================================================================
--- trunk/main.c 2008-11-22 13:48:46 UTC (rev 54)
+++ trunk/main.c 2008-11-24 05:32:17 UTC (rev 55)
@@ -6,7 +6,7 @@
#include <ncurses.h>
#include "text_window.h"
-#include "stat_window.h"
+#include "status_window.h"
#include "map_window.h"
#include "random.h"
#include "keyboard.h"
@@ -19,7 +19,7 @@
static struct char_struct main_char =
{
- "Foobar",
+ "Foobar the Apprentice",
{ 16, 16, 16, 16, 16, 16 },
0,
1,
@@ -54,7 +54,7 @@
text_window_create();
map_window_create();
- stat_window_create();
+ status_window_create();
invt_init(&main_char.inventory);
@@ -80,7 +80,7 @@
/* If text window is still existing, destroy it */
text_window_destroy();
map_window_destroy();
- stat_window_destroy();
+ status_window_destroy();
/* End ncurses library */
endwin();
@@ -103,6 +103,9 @@
endwin();
curs_set(0); /* Hide the cursor */
+ text_window_resize();
+ map_window_resize();
+ status_window_resize();
clear();
refresh();
}
@@ -137,7 +140,7 @@
map_window_update(map);
}
- stat_window_update(&main_char);
+ status_window_update(&main_char);
doupdate();
}
Modified: trunk/map_window.c
===================================================================
--- trunk/map_window.c 2008-11-22 13:48:46 UTC (rev 54)
+++ trunk/map_window.c 2008-11-24 05:32:17 UTC (rev 55)
@@ -3,51 +3,59 @@
#include <string.h>
#include <ncurses.h>
-#define MAPWND_MAXWIDTH (80)
-#define MAPWND_MAXHEIGHT (20)
-#define MAPWND_SCREENSIZE (MAPWND_MAXWIDTH * MAPWND_MAXHEIGHT)
+#define MAPWINDOW_MAXWIDTH (80)
+#define MAPWINDOW_MAXHEIGHT (20)
+#define MAPWINDOW_SCREENSIZE (MAPWINDOW_MAXWIDTH * MAPWINDOW_MAXHEIGHT)
-static WINDOW *border_wnd; /* Window handle */
+static WINDOW *map_wnd; /* Window handle */
void map_window_create(void)
{
- border_wnd = newwin(MAPWND_MAXHEIGHT, MAPWND_MAXWIDTH, 2, 0);
+ map_wnd = newwin(MAPWINDOW_MAXHEIGHT, MAPWINDOW_MAXWIDTH, 2, 0);
- if (!border_wnd) {
+ if (!map_wnd) {
fprintf(stderr, "map window creation failed!\n");
return;
}
- wattron(border_wnd, COLOR_PAIR(4));
- wbkgd(border_wnd, COLOR_PAIR(4));
+ wattron(map_wnd, COLOR_PAIR(4));
+ wbkgd(map_wnd, COLOR_PAIR(4));
- wrefresh(border_wnd);
+ wrefresh(map_wnd);
}
void map_window_destroy()
{
- if (border_wnd) {
+ if (map_wnd) {
/* Free resources consumed by the window */
- delwin(border_wnd);
- border_wnd = NULL;
+ delwin(map_wnd);
+ map_wnd = NULL;
}
}
+void map_window_resize(void)
+{
+ /* Reallocate storage for resized text window */
+ wresize(map_wnd, MAPWINDOW_MAXHEIGHT, MAPWINDOW_MAXWIDTH);
+}
+
+
+
void map_window_update(const chtype *map)
{
/* Set cursor to first position (upper left) in map window */
- wmove(border_wnd, 0, 0);
+ wmove(map_wnd, 0, 0);
/* Copy map to local map */
- for (int s = 0; s < MAPWND_SCREENSIZE; s++) {
- waddch(border_wnd, map[s]);
+ for (int s = 0; s < MAPWINDOW_SCREENSIZE; s++) {
+ waddch(map_wnd, map[s]);
}
- wnoutrefresh(border_wnd);
+ wnoutrefresh(map_wnd);
}
Modified: trunk/map_window.h
===================================================================
--- trunk/map_window.h 2008-11-22 13:48:46 UTC (rev 54)
+++ trunk/map_window.h 2008-11-24 05:32:17 UTC (rev 55)
@@ -5,6 +5,7 @@
void map_window_create(void);
void map_window_destroy(void);
+void map_window_resize(void);
void map_window_update(const chtype *m);
#endif // !DERACIEL_MAP_WINDOW_H
Deleted: trunk/stat_window.c
===================================================================
--- trunk/stat_window.c 2008-11-22 13:48:46 UTC (rev 54)
+++ trunk/stat_window.c 2008-11-24 05:32:17 UTC (rev 55)
@@ -1,73 +0,0 @@
-#include "stat_window.h"
-
-#include <string.h>
-#include <ncurses.h>
-
-#define BORDER_WND_MAXWIDTH (80)
-#define BORDER_WND_MAXHEIGHT (3)
-
-#define STATWINDOW_BORDER
-
-static WINDOW *border_wnd; /* Window handle */
-
-static void draw_border();
-
-
-void stat_window_create(void)
-{
- border_wnd = newwin(BORDER_WND_MAXHEIGHT, BORDER_WND_MAXWIDTH, 25-BORDER_WND_MAXHEIGHT, 0);
-
- if (!border_wnd) {
- fprintf(stderr, "stat window creation failed!\n");
- return;
- }
-
- wattron(border_wnd, COLOR_PAIR(3));
- wbkgd(border_wnd, COLOR_PAIR(3));
-
-#ifdef STATWINDOW_BORDER
- /* Redraw border with new dimensions */
- draw_border();
-#endif // !STATWINDOW_BORDER
-
- wrefresh(border_wnd);
-}
-
-
-
-void stat_window_destroy()
-{
- if (border_wnd) {
- /* Free resources consumed by the window */
- delwin(border_wnd);
- border_wnd = NULL;
- }
-}
-
-
-
-void draw_border()
-{
- wborder(border_wnd, 0, 0, 0, ' ', '/', '\\', ACS_VLINE, ACS_VLINE);
-}
-
-
-
-void stat_window_update(const struct char_struct *ch)
-{
-#ifdef STATWINDOW_BORDER
- /* Redraw border with new dimensions */
- draw_border();
-#endif // !STATWINDOW_BORDER
-
- mvwprintw(border_wnd, 1, 2, "$:%d HP:%d(%d) MP:%d(%d) St:%2d Dx:%2d Co:%2d Wi:%2d Wp:%2d Ch:%2d",
- *(uint32_t*)(ch->inventory.coins->user_data),
- ch->cur_hitpoints, ch->max_hitpoints, ch->cur_magic, ch->max_magic,
- ch->stats[STAT_STRENGTH], ch->stats[STAT_DEXTERITY], ch->stats[STAT_CONSTITUTION],
- ch->stats[STAT_WISDOM], ch->stats[STAT_WILLPOWER], ch->stats[STAT_CHARISMA]);
-
- mvwprintw(border_wnd, 2, 2, "%s Xp:%2d/%d T:%d S:%d",
- ch->name, ch->level, ch->experience, ch->turns, ch->score);
-
- wnoutrefresh(border_wnd);
-}
Deleted: trunk/stat_window.h
===================================================================
--- trunk/stat_window.h 2008-11-22 13:48:46 UTC (rev 54)
+++ trunk/stat_window.h 2008-11-24 05:32:17 UTC (rev 55)
@@ -1,11 +0,0 @@
-#ifndef DERACIEL_STAT_WINDOW_H
-#define DERACIEL_STAT_WINDOW_H
-
-#include "char.h"
-
-void stat_window_create(void);
-void stat_window_destroy(void);
-void stat_window_update(const struct char_struct *ch);
-
-#endif // !DERACIEL_STAT_WINDOW_H
-
Copied: trunk/status_window.c (from rev 54, trunk/stat_window.c)
===================================================================
--- trunk/status_window.c (rev 0)
+++ trunk/status_window.c 2008-11-24 05:32:17 UTC (rev 55)
@@ -0,0 +1,80 @@
+#include "status_window.h"
+
+#include <string.h>
+#include <ncurses.h>
+
+#define STATUSWINDOW_MAXWIDTH (80)
+#define STATUSWINDOW_MAXHEIGHT (3)
+#define STATUSWINDOW_BORDER
+
+static WINDOW *status_wnd; /* Window handle */
+
+static void draw_border();
+
+
+void status_window_create(void)
+{
+ status_wnd = newwin(STATUSWINDOW_MAXHEIGHT, STATUSWINDOW_MAXWIDTH, 25-STATUSWINDOW_MAXHEIGHT, 0);
+
+ if (!status_wnd) {
+ fprintf(stderr, "stat window creation failed!\n");
+ return;
+ }
+
+ wattron(status_wnd, COLOR_PAIR(3));
+ wbkgd(status_wnd, COLOR_PAIR(3));
+
+#ifdef STATUSWINDOW_BORDER
+ /* Redraw border with new dimensions */
+ draw_border();
+#endif // !STATUSWINDOW_BORDER
+
+ wrefresh(status_wnd);
+}
+
+
+
+void status_window_destroy()
+{
+ if (status_wnd) {
+ /* Free resources consumed by the window */
+ delwin(status_wnd);
+ status_wnd = NULL;
+ }
+}
+
+
+
+void status_window_resize(void)
+{
+ /* Reallocate storage for resized text window */
+ wresize(status_wnd, STATUSWINDOW_MAXHEIGHT, STATUSWINDOW_MAXWIDTH);
+}
+
+
+
+void draw_border()
+{
+ wborder(status_wnd, 0, 0, 0, ' ', '/', '\\', ACS_VLINE, ACS_VLINE);
+}
+
+
+
+void status_window_update(const struct char_struct *ch)
+{
+#ifdef STATUSWINDOW_BORDER
+ /* Redraw border with new dimensions */
+ draw_border();
+#endif // !STATUSWINDOW_BORDER
+
+ mvwprintw(status_wnd, 1, 2, "$:%d HP:%d(%d) MP:%d(%d) St:%2d Dx:%2d Co:%2d Wi:%2d Wp:%2d Ch:%2d",
+ *(uint32_t*)(ch->inventory.coins->user_data),
+ ch->cur_hitpoints, ch->max_hitpoints, ch->cur_magic, ch->max_magic,
+ ch->stats[STAT_STRENGTH], ch->stats[STAT_DEXTERITY], ch->stats[STAT_CONSTITUTION],
+ ch->stats[STAT_WISDOM], ch->stats[STAT_WILLPOWER], ch->stats[STAT_CHARISMA]);
+
+ mvwprintw(status_wnd, 2, 2, "%s Xp:%2d/%d T:%d S:%d",
+ ch->name, ch->level, ch->experience, ch->turns, ch->score);
+
+ wnoutrefresh(status_wnd);
+}
Property changes on: trunk/status_window.c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Copied: trunk/status_window.h (from rev 54, trunk/stat_window.h)
===================================================================
--- trunk/status_window.h (rev 0)
+++ trunk/status_window.h 2008-11-24 05:32:17 UTC (rev 55)
@@ -0,0 +1,12 @@
+#ifndef DERACIEL_STATUS_WINDOW_H
+#define DERACIEL_STATUS_WINDOW_H
+
+#include "char.h"
+
+void status_window_create(void);
+void status_window_destroy(void);
+void status_window_resize(void);
+void status_window_update(const struct char_struct *ch);
+
+#endif // !DERACIEL_STATUS_WINDOW_H
+
Property changes on: trunk/status_window.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:mergeinfo
+
Added: svn:eol-style
+ native
Modified: trunk/text_window.c
===================================================================
--- trunk/text_window.c 2008-11-22 13:48:46 UTC (rev 54)
+++ trunk/text_window.c 2008-11-24 05:32:17 UTC (rev 55)
@@ -3,8 +3,8 @@
#include <string.h>
#include <ncurses.h>
-#define BORDER_WND_MAXWIDTH (80)
-#define BORDER_WND_MAXHEIGHT (2)
+#define TEXTWINDOW_MAXWIDTH (80)
+#define TEXTWINDOW_MAXHEIGHT (2)
#define TEXTWINDOW_BORDER
static WINDOW *border_wnd; /* Window handle */
@@ -15,8 +15,8 @@
void text_window_create(void)
{
- border_wnd = newwin(BORDER_WND_MAXHEIGHT, BORDER_WND_MAXWIDTH, 0, 0);
- text_wnd = newwin(BORDER_WND_MAXHEIGHT-1, BORDER_WND_MAXWIDTH-2, 0, 1);
+ border_wnd = newwin(TEXTWINDOW_MAXHEIGHT, TEXTWINDOW_MAXWIDTH, 0, 0);
+ text_wnd = newwin(TEXTWINDOW_MAXHEIGHT-1, TEXTWINDOW_MAXWIDTH-2, 0, 1);
if (!border_wnd || !text_wnd) {
fprintf(stderr, "text window creation failed!\n");
@@ -51,6 +51,15 @@
+void text_window_resize(void)
+{
+ /* Reallocate storage for resized text window */
+ wresize(border_wnd, TEXTWINDOW_MAXHEIGHT, TEXTWINDOW_MAXWIDTH);
+ wresize(text_wnd, TEXTWINDOW_MAXHEIGHT-1, TEXTWINDOW_MAXWIDTH-2);
+}
+
+
+
void text_window_out(const char *string)
{
#ifdef TEXTWINDOW_BORDER
Modified: trunk/text_window.h
===================================================================
--- trunk/text_window.h 2008-11-22 13:48:46 UTC (rev 54)
+++ trunk/text_window.h 2008-11-24 05:32:17 UTC (rev 55)
@@ -3,6 +3,7 @@
void text_window_create(void);
void text_window_destroy(void);
+void text_window_resize(void);
void text_window_out(const char *string);
void text_window_clear(void);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <lor...@us...> - 2008-11-22 13:48:56
|
Revision: 54
http://deraciel.svn.sourceforge.net/deraciel/?rev=54&view=rev
Author: lordhoto
Date: 2008-11-22 13:48:46 +0000 (Sat, 22 Nov 2008)
Log Message:
-----------
Fixed turn/score output in stat window.
Modified Paths:
--------------
trunk/stat_window.c
Modified: trunk/stat_window.c
===================================================================
--- trunk/stat_window.c 2008-11-22 13:47:48 UTC (rev 53)
+++ trunk/stat_window.c 2008-11-22 13:48:46 UTC (rev 54)
@@ -67,7 +67,7 @@
ch->stats[STAT_WISDOM], ch->stats[STAT_WILLPOWER], ch->stats[STAT_CHARISMA]);
mvwprintw(border_wnd, 2, 2, "%s Xp:%2d/%d T:%d S:%d",
- ch->name, ch->level, ch->experience, ch->score, ch->turns);
+ ch->name, ch->level, ch->experience, ch->turns, ch->score);
wnoutrefresh(border_wnd);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <lor...@us...> - 2008-11-22 13:47:54
|
Revision: 53
http://deraciel.svn.sourceforge.net/deraciel/?rev=53&view=rev
Author: lordhoto
Date: 2008-11-22 13:47:48 +0000 (Sat, 22 Nov 2008)
Log Message:
-----------
Use char_struct instead of plain stat values to update the stat window.
Modified Paths:
--------------
trunk/char.h
trunk/main.c
trunk/stat.h
trunk/stat_window.c
trunk/stat_window.h
Modified: trunk/char.h
===================================================================
--- trunk/char.h 2008-11-22 13:18:00 UTC (rev 52)
+++ trunk/char.h 2008-11-22 13:47:48 UTC (rev 53)
@@ -6,17 +6,6 @@
#include "inventory.h"
#include "stat.h"
-enum
-{
- STAT_STRENGTH,
- STAT_DEXTERITY,
- STAT_WISDOM,
- STAT_WILLPOWER,
- STAT_CONSTITUTION,
- STAT_CHARISMA,
- STAT_MAX_STATS
-};
-
struct char_struct
{
char name[32];
@@ -26,6 +15,15 @@
uint32_t experience;
uint8_t level;
+ uint32_t turns;
+ uint32_t score;
+
+ int16_t cur_hitpoints;
+ int16_t max_hitpoints;
+
+ int16_t cur_magic;
+ int16_t max_magic;
+
struct invt_struct inventory;
};
Modified: trunk/main.c
===================================================================
--- trunk/main.c 2008-11-22 13:18:00 UTC (rev 52)
+++ trunk/main.c 2008-11-22 13:47:48 UTC (rev 53)
@@ -17,6 +17,21 @@
static void finish(const int);
static void test_keyhandler(const int key);
+static struct char_struct main_char =
+{
+ "Foobar",
+ { 16, 16, 16, 16, 16, 16 },
+ 0,
+ 1,
+ 0,
+ 0,
+ 16,
+ 16,
+ 10,
+ 10,
+ { 0 }
+};
+
int main(int argc, char **argv)
{
signal(SIGINT, finish); /* arrange interrupts to terminate */
@@ -41,6 +56,8 @@
map_window_create();
stat_window_create();
+ invt_init(&main_char.inventory);
+
/* Create keyboard handler */
keyreader_create();
@@ -50,6 +67,8 @@
/* Let thread work */
while(1) { sleep(5); };
+ invt_uninit(&main_char.inventory);
+
finish(0);
return 0;
}
@@ -73,7 +92,6 @@
static int counter = 0;
static chtype map[80*20];
-static stat_t stats[STAT_MAX_STATS] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14};
static void test_keyhandler(const int key)
{
@@ -119,7 +137,7 @@
map_window_update(map);
}
- stat_window_update(stats);
+ stat_window_update(&main_char);
doupdate();
}
Modified: trunk/stat.h
===================================================================
--- trunk/stat.h 2008-11-22 13:18:00 UTC (rev 52)
+++ trunk/stat.h 2008-11-22 13:47:48 UTC (rev 53)
@@ -6,21 +6,12 @@
typedef uint32_t stat_t;
enum {
- STAT_CUR_HITPOINTS,
- STAT_MAX_HITPOINTS,
- STAT_CUR_MAGIC,
- STAT_MAX_MAGIC,
STAT_STRENGTH,
STAT_DEXTERITY,
STAT_WISDOM,
STAT_WILLPOWER,
STAT_CONSTITUTION,
STAT_CHARISMA,
- STAT_XP_LEVEL,
- STAT_EXPERIENCE,
- STAT_SCORE,
- STAT_GOLD,
- STAT_TURNS,
STAT_MAX_STATS
};
Modified: trunk/stat_window.c
===================================================================
--- trunk/stat_window.c 2008-11-22 13:18:00 UTC (rev 52)
+++ trunk/stat_window.c 2008-11-22 13:47:48 UTC (rev 53)
@@ -53,7 +53,7 @@
-void stat_window_update(const stat_t *stats)
+void stat_window_update(const struct char_struct *ch)
{
#ifdef STATWINDOW_BORDER
/* Redraw border with new dimensions */
@@ -61,13 +61,13 @@
#endif // !STATWINDOW_BORDER
mvwprintw(border_wnd, 1, 2, "$:%d HP:%d(%d) MP:%d(%d) St:%2d Dx:%2d Co:%2d Wi:%2d Wp:%2d Ch:%2d",
- stats[STAT_GOLD],
- stats[STAT_CUR_HITPOINTS], stats[STAT_MAX_HITPOINTS], stats[STAT_CUR_MAGIC], stats[STAT_MAX_MAGIC],
- stats[STAT_STRENGTH], stats[STAT_DEXTERITY], stats[STAT_CONSTITUTION],
- stats[STAT_WISDOM], stats[STAT_WILLPOWER], stats[STAT_CHARISMA]);
+ *(uint32_t*)(ch->inventory.coins->user_data),
+ ch->cur_hitpoints, ch->max_hitpoints, ch->cur_magic, ch->max_magic,
+ ch->stats[STAT_STRENGTH], ch->stats[STAT_DEXTERITY], ch->stats[STAT_CONSTITUTION],
+ ch->stats[STAT_WISDOM], ch->stats[STAT_WILLPOWER], ch->stats[STAT_CHARISMA]);
- mvwprintw(border_wnd, 2, 2, "Xp:%2d/%d T:%d S:%d",
- stats[STAT_XP_LEVEL], stats[STAT_EXPERIENCE], stats[STAT_SCORE], stats[STAT_TURNS]);
+ mvwprintw(border_wnd, 2, 2, "%s Xp:%2d/%d T:%d S:%d",
+ ch->name, ch->level, ch->experience, ch->score, ch->turns);
wnoutrefresh(border_wnd);
}
Modified: trunk/stat_window.h
===================================================================
--- trunk/stat_window.h 2008-11-22 13:18:00 UTC (rev 52)
+++ trunk/stat_window.h 2008-11-22 13:47:48 UTC (rev 53)
@@ -1,11 +1,11 @@
#ifndef DERACIEL_STAT_WINDOW_H
#define DERACIEL_STAT_WINDOW_H
-#include "stat.h"
+#include "char.h"
void stat_window_create(void);
void stat_window_destroy(void);
-void stat_window_update(const stat_t *stats);
+void stat_window_update(const struct char_struct *ch);
#endif // !DERACIEL_STAT_WINDOW_H
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sch...@us...> - 2008-11-22 13:18:09
|
Revision: 52
http://deraciel.svn.sourceforge.net/deraciel/?rev=52&view=rev
Author: schnippi001
Date: 2008-11-22 13:18:00 +0000 (Sat, 22 Nov 2008)
Log Message:
-----------
CMake based build system written by xororand. Thank you!
Modified Paths:
--------------
trunk/INSTALL
trunk/main.c
Added Paths:
-----------
trunk/CMakeLists.txt
trunk/_cmake-distclean.bash
Added: trunk/CMakeLists.txt
===================================================================
--- trunk/CMakeLists.txt (rev 0)
+++ trunk/CMakeLists.txt 2008-11-22 13:18:00 UTC (rev 52)
@@ -0,0 +1,27 @@
+cmake_minimum_required(VERSION 2.6)
+
+project(deraciel)
+SET(CMAKE_C_FLAGS "-Wall -Werror -std=c99")
+
+# requirements
+find_library( NCURSES_LIBRARY ncurses )
+if( NCURSES_LIBRARY )
+ message( STATUS "ncurses library found: ${NCURSES_LIBRARY}" )
+else( NCURSES_LIBRARY )
+ message( FATAL_ERROR "ncurses library not found". )
+endif( NCURSES_LIBRARY )
+
+include_directories(
+ ${NCURSES_INCLUDE_DIRS}
+)
+link_directories(
+ ${NCURSES_LIBRARY_DIRS}
+)
+
+# build
+file(GLOB DERACIEL_SOURCES *.c)
+add_executable(deraciel ${DERACIEL_SOURCES})
+target_link_libraries(deraciel
+ ${NCURSES_LIBRARY}
+ pthread
+)
Property changes on: trunk/CMakeLists.txt
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: trunk/INSTALL
===================================================================
--- trunk/INSTALL 2008-11-22 12:55:59 UTC (rev 51)
+++ trunk/INSTALL 2008-11-22 13:18:00 UTC (rev 52)
@@ -1,10 +1,15 @@
Compile
=======
-clear && gcc -g -std=c99 -Wall -o main *.c -lncurses -lpthread
+cmake .
+make
-
Run
===
-./main
+./deraciel
+
+
+Clean up
+========
+./_cmake-distclean.bash
Added: trunk/_cmake-distclean.bash
===================================================================
--- trunk/_cmake-distclean.bash (rev 0)
+++ trunk/_cmake-distclean.bash 2008-11-22 13:18:00 UTC (rev 52)
@@ -0,0 +1,27 @@
+#!/bin/bash
+find . -name "*.cmake" |while read f; do
+ echo "rm ${f}"
+ rm "${f}"
+done
+
+find . -name "CMakeCache.txt" |while read f; do
+ echo "rm ${f}"
+ rm "${f}"
+done
+
+find . -name "Makefile" |while read f; do
+ echo "rm ${f}"
+ rm "${f}"
+done
+
+find . -type d -name CMakeFiles |while read d; do
+ echo "rm -r ${d}"
+ rm -r "${d}"
+done
+
+find . -type d -name CMakeTmp |while read d; do
+ echo "rm -r ${d}"
+ rm -r "${d}"
+done
+
+
Property changes on: trunk/_cmake-distclean.bash
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: trunk/main.c
===================================================================
--- trunk/main.c 2008-11-22 12:55:59 UTC (rev 51)
+++ trunk/main.c 2008-11-22 13:18:00 UTC (rev 52)
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <signal.h>
#include <time.h>
+#include <unistd.h>
#include <ncurses.h>
#include "text_window.h"
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sch...@us...> - 2008-11-22 12:56:08
|
Revision: 51
http://deraciel.svn.sourceforge.net/deraciel/?rev=51&view=rev
Author: schnippi001
Date: 2008-11-22 12:55:59 +0000 (Sat, 22 Nov 2008)
Log Message:
-----------
See last commit log
Modified Paths:
--------------
trunk/stat_window.c
trunk/text_window.c
Modified: trunk/stat_window.c
===================================================================
--- trunk/stat_window.c 2008-11-22 12:41:59 UTC (rev 50)
+++ trunk/stat_window.c 2008-11-22 12:55:59 UTC (rev 51)
@@ -55,9 +55,6 @@
void stat_window_update(const stat_t *stats)
{
- /* Clear window from screen */
-// wclear(border_wnd);
-
#ifdef STATWINDOW_BORDER
/* Redraw border with new dimensions */
draw_border();
Modified: trunk/text_window.c
===================================================================
--- trunk/text_window.c 2008-11-22 12:41:59 UTC (rev 50)
+++ trunk/text_window.c 2008-11-22 12:55:59 UTC (rev 51)
@@ -53,9 +53,6 @@
void text_window_out(const char *string)
{
-// wclear(border_wnd);
-// wclear(text_wnd);
-
#ifdef TEXTWINDOW_BORDER
/* Redraw border with new dimensions */
draw_border();
@@ -71,9 +68,6 @@
void text_window_clear()
{
-// wclear(border_wnd);
-// wclear(text_wnd);
-
#ifdef TEXTWINDOW_BORDER
/* Redraw border with new dimensions */
draw_border();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sch...@us...> - 2008-11-22 12:42:08
|
Revision: 50
http://deraciel.svn.sourceforge.net/deraciel/?rev=50&view=rev
Author: schnippi001
Date: 2008-11-22 12:41:59 +0000 (Sat, 22 Nov 2008)
Log Message:
-----------
Removed massive flickering while running on virtual terminals/running
over ssh
Modified Paths:
--------------
trunk/main.c
trunk/stat_window.c
trunk/text_window.c
Modified: trunk/main.c
===================================================================
--- trunk/main.c 2008-11-22 12:30:44 UTC (rev 49)
+++ trunk/main.c 2008-11-22 12:41:59 UTC (rev 50)
@@ -71,7 +71,7 @@
}
static int counter = 0;
-static chtype map[80*20 + 1];
+static chtype map[80*20];
static stat_t stats[STAT_MAX_STATS] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14};
static void test_keyhandler(const int key)
@@ -95,17 +95,15 @@
}
if (counter == 2) {
- text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. ");
+ text_window_out("Ein etwas laengerer Text 2");
}
if (counter == 3) {
- text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd guber");
+ text_window_out("Und Text 3");
counter = 0;
}
}
- map[80*20] = '\n';
-
if (key == KEY_LEFT) {
for (int i = 0; i < 80*20; i++) {
map[i] = 'o';
Modified: trunk/stat_window.c
===================================================================
--- trunk/stat_window.c 2008-11-22 12:30:44 UTC (rev 49)
+++ trunk/stat_window.c 2008-11-22 12:41:59 UTC (rev 50)
@@ -56,7 +56,7 @@
void stat_window_update(const stat_t *stats)
{
/* Clear window from screen */
- wclear(border_wnd);
+// wclear(border_wnd);
#ifdef STATWINDOW_BORDER
/* Redraw border with new dimensions */
Modified: trunk/text_window.c
===================================================================
--- trunk/text_window.c 2008-11-22 12:30:44 UTC (rev 49)
+++ trunk/text_window.c 2008-11-22 12:41:59 UTC (rev 50)
@@ -53,8 +53,8 @@
void text_window_out(const char *string)
{
- wclear(border_wnd);
- wclear(text_wnd);
+// wclear(border_wnd);
+// wclear(text_wnd);
#ifdef TEXTWINDOW_BORDER
/* Redraw border with new dimensions */
@@ -64,15 +64,15 @@
wmove(text_wnd, 0, 0);
wprintw(text_wnd, string);
- wrefresh(border_wnd);
- wrefresh(text_wnd);
+ wnoutrefresh(border_wnd);
+ wnoutrefresh(text_wnd);
}
void text_window_clear()
{
- wclear(border_wnd);
- wclear(text_wnd);
+// wclear(border_wnd);
+// wclear(text_wnd);
#ifdef TEXTWINDOW_BORDER
/* Redraw border with new dimensions */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sch...@us...> - 2008-11-22 12:30:50
|
Revision: 49
http://deraciel.svn.sourceforge.net/deraciel/?rev=49&view=rev
Author: schnippi001
Date: 2008-11-22 12:30:44 +0000 (Sat, 22 Nov 2008)
Log Message:
-----------
Separated stats enumeration from player file
Added stats and map windows
Removed multiline output
Modified Paths:
--------------
trunk/INSTALL
trunk/char.h
trunk/keyboard.c
trunk/keyboard.h
trunk/main.c
trunk/text_window.c
trunk/text_window.h
Added Paths:
-----------
trunk/map_window.c
trunk/map_window.h
trunk/stat.h
trunk/stat_window.c
trunk/stat_window.h
Modified: trunk/INSTALL
===================================================================
--- trunk/INSTALL 2008-11-22 01:54:53 UTC (rev 48)
+++ trunk/INSTALL 2008-11-22 12:30:44 UTC (rev 49)
@@ -1,7 +1,7 @@
Compile
=======
-clear && gcc -std=c99 -o main *.c -lncurses -lform -lpthread
+clear && gcc -g -std=c99 -Wall -o main *.c -lncurses -lpthread
Run
Modified: trunk/char.h
===================================================================
--- trunk/char.h 2008-11-22 01:54:53 UTC (rev 48)
+++ trunk/char.h 2008-11-22 12:30:44 UTC (rev 49)
@@ -4,6 +4,7 @@
#include <stdint.h>
#include "inventory.h"
+#include "stat.h"
enum
{
@@ -20,7 +21,7 @@
{
char name[32];
- uint8_t stats[STAT_MAX_STATS];
+ stat_t stats[STAT_MAX_STATS];
uint32_t experience;
uint8_t level;
@@ -28,5 +29,5 @@
struct invt_struct inventory;
};
-#endif
+#endif // !DERACIEL_CHAR_H
Modified: trunk/keyboard.c
===================================================================
--- trunk/keyboard.c 2008-11-22 01:54:53 UTC (rev 48)
+++ trunk/keyboard.c 2008-11-22 12:30:44 UTC (rev 49)
@@ -6,45 +6,58 @@
#include <pthread.h>
-pthread_t keyreader_thread;
+static pthread_t keyreader_thread;
static void (*handler_cb)(const int key);
-
-
+/*
+ The keyreader is an infinite loop that gets one character at iteration and
+ passes it to a keyboard handling callback. The callback then can respond
+ appropriately to the given key. This function is running inside a thread
+ created by keyreader_create().
+*/
static void *keyreader(void *unused)
{
- int tid;
- int ch;
+ /* This variable will hold the keycode of pressed key */
+ int key;
+ /* Run an infinite loop */
while(1) {
- ch = getch();
- if (handler_cb) handler_cb(ch);
+ /* Fetch a key from keyboard buffer */
+ key = getch();
+
+ /* If handler callback is specified, delegate the previously
+ fetched key to it, else throw an error message */
+ if (handler_cb) {
+ handler_cb(key);
+ } else {
+ fprintf(stderr, "ERROR: Handler callback was NULL!\n");
+ }
}
+
+ return NULL;
}
-
+/*
+ Creates a thread that runs keyreader().
+*/
void keyreader_create()
{
int rc = pthread_create(&keyreader_thread, NULL, keyreader, NULL);
- if (rc){
- printf("ERROR; return code from pthread_create() is %d\n", rc);
+ if (rc) {
+ fprintf(stderr, "ERROR: Keyreader thread creation failed! (error code: %d)\n", rc);
exit(-1);
}
}
-void keyreader_destroy()
-{
-}
-
-
-
void keyreader_set_handler(void(*cb)(const int key))
{
- // TODO: Error handling
+ /* If the callback is not NULL set it as active keyboard handling function */
if (cb) {
handler_cb = cb;
+ } else {
+ fprintf(stderr, "ERROR: Specified callback was NULL!\n");
}
}
Modified: trunk/keyboard.h
===================================================================
--- trunk/keyboard.h 2008-11-22 01:54:53 UTC (rev 48)
+++ trunk/keyboard.h 2008-11-22 12:30:44 UTC (rev 49)
@@ -5,8 +5,6 @@
void keyreader_create(void);
-void keyreader_destroy(void);
-
void keyreader_set_handler(void(*cb)(const int key));
#endif // !DERACIEL_KEYBOARD_H
Modified: trunk/main.c
===================================================================
--- trunk/main.c 2008-11-22 01:54:53 UTC (rev 48)
+++ trunk/main.c 2008-11-22 12:30:44 UTC (rev 49)
@@ -2,21 +2,18 @@
#include <stdio.h>
#include <signal.h>
#include <time.h>
+#include <ncurses.h>
-#include <curses.h>
-
#include "text_window.h"
+#include "stat_window.h"
+#include "map_window.h"
#include "random.h"
#include "keyboard.h"
-void finish(const int);
-void repaint_windows(void);
-WINDOW *MAPWND;
-WINDOW *STATWND;
-
#define KEY_ESCAPE 27
+static void finish(const int);
static void test_keyhandler(const int key);
int main(int argc, char **argv)
@@ -33,11 +30,15 @@
start_color();
init_pair(1, COLOR_WHITE, COLOR_BLUE);
init_pair(2, COLOR_BLACK, COLOR_YELLOW);
+ init_pair(3, COLOR_WHITE, COLOR_RED);
+ init_pair(4, COLOR_WHITE, COLOR_GREEN);
clear();
refresh();
text_window_create();
+ map_window_create();
+ stat_window_create();
/* Create keyboard handler */
keyreader_create();
@@ -48,7 +49,6 @@
/* Let thread work */
while(1) { sleep(5); };
- text_window_destroy();
finish(0);
return 0;
}
@@ -59,6 +59,8 @@
{
/* If text window is still existing, destroy it */
text_window_destroy();
+ map_window_destroy();
+ stat_window_destroy();
/* End ncurses library */
endwin();
@@ -69,9 +71,13 @@
}
static int counter = 0;
+static chtype map[80*20 + 1];
+static stat_t stats[STAT_MAX_STATS] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14};
static void test_keyhandler(const int key)
{
+ text_window_clear();
+
if (key == KEY_ESCAPE) finish(0);
if (key == KEY_RESIZE) {
@@ -80,7 +86,6 @@
clear();
refresh();
- text_window_resize();
}
if (key == KEY_DOWN) {
@@ -90,12 +95,32 @@
}
if (counter == 2) {
- 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");
+ text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. ");
}
if (counter == 3) {
- 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");
+ text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd guber");
counter = 0;
}
}
+
+ map[80*20] = '\n';
+
+ if (key == KEY_LEFT) {
+ for (int i = 0; i < 80*20; i++) {
+ map[i] = 'o';
+ }
+ map_window_update(map);
+ }
+
+ if (key == KEY_RIGHT) {
+ for (int i = 0; i < 80*20; i++) {
+ map[i] = '*';
+ }
+ map_window_update(map);
+ }
+
+ stat_window_update(stats);
+
+ doupdate();
}
Added: trunk/map_window.c
===================================================================
--- trunk/map_window.c (rev 0)
+++ trunk/map_window.c 2008-11-22 12:30:44 UTC (rev 49)
@@ -0,0 +1,53 @@
+#include "map_window.h"
+
+#include <string.h>
+#include <ncurses.h>
+
+#define MAPWND_MAXWIDTH (80)
+#define MAPWND_MAXHEIGHT (20)
+#define MAPWND_SCREENSIZE (MAPWND_MAXWIDTH * MAPWND_MAXHEIGHT)
+
+static WINDOW *border_wnd; /* Window handle */
+
+
+
+void map_window_create(void)
+{
+ border_wnd = newwin(MAPWND_MAXHEIGHT, MAPWND_MAXWIDTH, 2, 0);
+
+ if (!border_wnd) {
+ fprintf(stderr, "map window creation failed!\n");
+ return;
+ }
+
+ wattron(border_wnd, COLOR_PAIR(4));
+ wbkgd(border_wnd, COLOR_PAIR(4));
+
+ wrefresh(border_wnd);
+}
+
+
+
+void map_window_destroy()
+{
+ if (border_wnd) {
+ /* Free resources consumed by the window */
+ delwin(border_wnd);
+ border_wnd = NULL;
+ }
+}
+
+
+
+void map_window_update(const chtype *map)
+{
+ /* Set cursor to first position (upper left) in map window */
+ wmove(border_wnd, 0, 0);
+
+ /* Copy map to local map */
+ for (int s = 0; s < MAPWND_SCREENSIZE; s++) {
+ waddch(border_wnd, map[s]);
+ }
+
+ wnoutrefresh(border_wnd);
+}
Property changes on: trunk/map_window.c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/map_window.h
===================================================================
--- trunk/map_window.h (rev 0)
+++ trunk/map_window.h 2008-11-22 12:30:44 UTC (rev 49)
@@ -0,0 +1,10 @@
+#ifndef DERACIEL_MAP_WINDOW_H
+#define DERACIEL_MAP_WINDOW_H
+
+#include <ncurses.h>
+
+void map_window_create(void);
+void map_window_destroy(void);
+void map_window_update(const chtype *m);
+
+#endif // !DERACIEL_MAP_WINDOW_H
Property changes on: trunk/map_window.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/stat.h
===================================================================
--- trunk/stat.h (rev 0)
+++ trunk/stat.h 2008-11-22 12:30:44 UTC (rev 49)
@@ -0,0 +1,27 @@
+#ifndef DERACIEL_STAT_H
+#define DERACIEL_STAT_H
+
+#include <stdint.h>
+
+typedef uint32_t stat_t;
+
+enum {
+ STAT_CUR_HITPOINTS,
+ STAT_MAX_HITPOINTS,
+ STAT_CUR_MAGIC,
+ STAT_MAX_MAGIC,
+ STAT_STRENGTH,
+ STAT_DEXTERITY,
+ STAT_WISDOM,
+ STAT_WILLPOWER,
+ STAT_CONSTITUTION,
+ STAT_CHARISMA,
+ STAT_XP_LEVEL,
+ STAT_EXPERIENCE,
+ STAT_SCORE,
+ STAT_GOLD,
+ STAT_TURNS,
+ STAT_MAX_STATS
+};
+
+#endif // !DERACIEL_STAT_H
Property changes on: trunk/stat.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/stat_window.c
===================================================================
--- trunk/stat_window.c (rev 0)
+++ trunk/stat_window.c 2008-11-22 12:30:44 UTC (rev 49)
@@ -0,0 +1,76 @@
+#include "stat_window.h"
+
+#include <string.h>
+#include <ncurses.h>
+
+#define BORDER_WND_MAXWIDTH (80)
+#define BORDER_WND_MAXHEIGHT (3)
+
+#define STATWINDOW_BORDER
+
+static WINDOW *border_wnd; /* Window handle */
+
+static void draw_border();
+
+
+void stat_window_create(void)
+{
+ border_wnd = newwin(BORDER_WND_MAXHEIGHT, BORDER_WND_MAXWIDTH, 25-BORDER_WND_MAXHEIGHT, 0);
+
+ if (!border_wnd) {
+ fprintf(stderr, "stat window creation failed!\n");
+ return;
+ }
+
+ wattron(border_wnd, COLOR_PAIR(3));
+ wbkgd(border_wnd, COLOR_PAIR(3));
+
+#ifdef STATWINDOW_BORDER
+ /* Redraw border with new dimensions */
+ draw_border();
+#endif // !STATWINDOW_BORDER
+
+ wrefresh(border_wnd);
+}
+
+
+
+void stat_window_destroy()
+{
+ if (border_wnd) {
+ /* Free resources consumed by the window */
+ delwin(border_wnd);
+ border_wnd = NULL;
+ }
+}
+
+
+
+void draw_border()
+{
+ wborder(border_wnd, 0, 0, 0, ' ', '/', '\\', ACS_VLINE, ACS_VLINE);
+}
+
+
+
+void stat_window_update(const stat_t *stats)
+{
+ /* Clear window from screen */
+ wclear(border_wnd);
+
+#ifdef STATWINDOW_BORDER
+ /* Redraw border with new dimensions */
+ draw_border();
+#endif // !STATWINDOW_BORDER
+
+ mvwprintw(border_wnd, 1, 2, "$:%d HP:%d(%d) MP:%d(%d) St:%2d Dx:%2d Co:%2d Wi:%2d Wp:%2d Ch:%2d",
+ stats[STAT_GOLD],
+ stats[STAT_CUR_HITPOINTS], stats[STAT_MAX_HITPOINTS], stats[STAT_CUR_MAGIC], stats[STAT_MAX_MAGIC],
+ stats[STAT_STRENGTH], stats[STAT_DEXTERITY], stats[STAT_CONSTITUTION],
+ stats[STAT_WISDOM], stats[STAT_WILLPOWER], stats[STAT_CHARISMA]);
+
+ mvwprintw(border_wnd, 2, 2, "Xp:%2d/%d T:%d S:%d",
+ stats[STAT_XP_LEVEL], stats[STAT_EXPERIENCE], stats[STAT_SCORE], stats[STAT_TURNS]);
+
+ wnoutrefresh(border_wnd);
+}
Property changes on: trunk/stat_window.c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/stat_window.h
===================================================================
--- trunk/stat_window.h (rev 0)
+++ trunk/stat_window.h 2008-11-22 12:30:44 UTC (rev 49)
@@ -0,0 +1,11 @@
+#ifndef DERACIEL_STAT_WINDOW_H
+#define DERACIEL_STAT_WINDOW_H
+
+#include "stat.h"
+
+void stat_window_create(void);
+void stat_window_destroy(void);
+void stat_window_update(const stat_t *stats);
+
+#endif // !DERACIEL_STAT_WINDOW_H
+
Property changes on: trunk/stat_window.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Modified: trunk/text_window.c
===================================================================
--- trunk/text_window.c 2008-11-22 01:54:53 UTC (rev 48)
+++ trunk/text_window.c 2008-11-22 12:30:44 UTC (rev 49)
@@ -1,18 +1,15 @@
#include "text_window.h"
#include <string.h>
-#include <form.h>
+#include <ncurses.h>
#define BORDER_WND_MAXWIDTH (80)
#define BORDER_WND_MAXHEIGHT (2)
-#define TEXTWINDOW_LINEBUFFER_SIZE (3*78 + 1) // 3 lines * 78 characters + '\n'
#define TEXTWINDOW_BORDER
static WINDOW *border_wnd; /* Window handle */
static WINDOW *text_wnd; /* Window handle */
-static char linebuffer[TEXTWINDOW_LINEBUFFER_SIZE];
-static void repaint(void);
static void draw_border();
@@ -27,9 +24,15 @@
}
wattron(border_wnd, COLOR_PAIR(1));
- wbkgd(text_wnd, COLOR_PAIR(2));
+ wbkgd(text_wnd, COLOR_PAIR(1));
- repaint();
+#ifdef TEXTWINDOW_BORDER
+ /* Redraw border with new dimensions */
+ draw_border();
+#endif // !TEXTWINDOW_BORDER
+
+ wrefresh(border_wnd);
+ wrefresh(text_wnd);
}
@@ -37,10 +40,6 @@
void text_window_destroy()
{
if (border_wnd) {
- /* Clear window from screen */
- wclear(border_wnd);
- wrefresh(border_wnd);
-
/* Free resources consumed by the window */
delwin(text_wnd);
text_wnd = NULL;
@@ -52,64 +51,40 @@
-void text_window_resize(void)
+void text_window_out(const char *string)
{
- /* Clear window from screen */
wclear(border_wnd);
wclear(text_wnd);
- /* Reallocate storage for resized text window */
- wresize(border_wnd, BORDER_WND_MAXHEIGHT, BORDER_WND_MAXWIDTH);
- wresize(text_wnd, BORDER_WND_MAXHEIGHT-1, BORDER_WND_MAXWIDTH-2);
+#ifdef TEXTWINDOW_BORDER
+ /* Redraw border with new dimensions */
+ draw_border();
+#endif // !TEXTWINDOW_BORDER
- repaint();
-}
+ wmove(text_wnd, 0, 0);
+ wprintw(text_wnd, string);
-
-
-void text_window_out(const char *string)
-{
- 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);
-
- int lines = (mod == 0 ? 0 : 1) + strlen(linebuffer)/(BORDER_WND_MAXWIDTH-2);
-
- wresize(text_wnd, lines, BORDER_WND_MAXWIDTH-2);
- wresize(border_wnd, lines+1, BORDER_WND_MAXWIDTH);
-
- repaint();
+ wrefresh(border_wnd);
+ wrefresh(text_wnd);
}
-
-void draw_border()
+void text_window_clear()
{
- wborder(border_wnd, 0, 0, ' ', 0, ACS_VLINE, ACS_VLINE, '\\', '/');
-}
-
-
-
-void repaint()
-{
- /* Clear window from screen */
wclear(border_wnd);
wclear(text_wnd);
#ifdef TEXTWINDOW_BORDER
/* Redraw border with new dimensions */
draw_border();
-#endif // TEXTWINDOW_BORDER
+#endif // !TEXTWINDOW_BORDER
- wmove(text_wnd, 0, 0);
- wprintw(text_wnd, linebuffer);
-
wnoutrefresh(border_wnd);
wnoutrefresh(text_wnd);
- doupdate();
}
+
+
+void draw_border()
+{
+ wborder(border_wnd, 0, 0, ' ', 0, ACS_VLINE, ACS_VLINE, '\\', '/');
+}
Modified: trunk/text_window.h
===================================================================
--- trunk/text_window.h 2008-11-22 01:54:53 UTC (rev 48)
+++ trunk/text_window.h 2008-11-22 12:30:44 UTC (rev 49)
@@ -1,12 +1,10 @@
-#ifndef _TEXT_WINDOW_H
-#define _TEXT_WINDOW_H
+#ifndef DERACIEL_TEXT_WINDOW_H
+#define DERACIEL_TEXT_WINDOW_H
-#include <curses.h>
-
void text_window_create(void);
void text_window_destroy(void);
-void text_window_resize(void);
void text_window_out(const char *string);
+void text_window_clear(void);
-#endif // _TEXT_WINDOW_H
+#endif // !DERACIEL_TEXT_WINDOW_H
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sch...@us...> - 2008-11-22 01:55:03
|
Revision: 48
http://deraciel.svn.sourceforge.net/deraciel/?rev=48&view=rev
Author: schnippi001
Date: 2008-11-22 01:54:53 +0000 (Sat, 22 Nov 2008)
Log Message:
-----------
Added sleep to while loop, limiting cpu usage
Modified Paths:
--------------
trunk/main.c
Modified: trunk/main.c
===================================================================
--- trunk/main.c 2008-11-22 01:46:22 UTC (rev 47)
+++ trunk/main.c 2008-11-22 01:54:53 UTC (rev 48)
@@ -37,8 +37,6 @@
clear();
refresh();
- //nocbreak();
-
text_window_create();
/* Create keyboard handler */
@@ -48,7 +46,7 @@
keyreader_set_handler(test_keyhandler);
/* Let thread work */
- while(1);
+ while(1) { sleep(5); };
text_window_destroy();
finish(0);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sch...@us...> - 2008-11-22 01:46:25
|
Revision: 47
http://deraciel.svn.sourceforge.net/deraciel/?rev=47&view=rev
Author: schnippi001
Date: 2008-11-22 01:46:22 +0000 (Sat, 22 Nov 2008)
Log Message:
-----------
Removed superfluous lines
Modified Paths:
--------------
trunk/main.c
Modified: trunk/main.c
===================================================================
--- trunk/main.c 2008-11-22 01:43:10 UTC (rev 46)
+++ trunk/main.c 2008-11-22 01:46:22 UTC (rev 47)
@@ -97,11 +97,7 @@
if (counter == 3) {
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");
+ counter = 0;
}
-
- if (counter == 4) {
- text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
- counter = 1;
- }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sch...@us...> - 2008-11-22 01:43:24
|
Revision: 46
http://deraciel.svn.sourceforge.net/deraciel/?rev=46&view=rev
Author: schnippi001
Date: 2008-11-22 01:43:10 +0000 (Sat, 22 Nov 2008)
Log Message:
-----------
Text output via key handler function (use down key and escape)
Modified Paths:
--------------
trunk/main.c
Modified: trunk/main.c
===================================================================
--- trunk/main.c 2008-11-22 01:35:25 UTC (rev 45)
+++ trunk/main.c 2008-11-22 01:43:10 UTC (rev 46)
@@ -44,42 +44,7 @@
/* Create keyboard handler */
keyreader_create();
- int ch;
-
-// 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();
-// }
-
+ /* Assign key handler callback */
keyreader_set_handler(test_keyhandler);
/* Let thread work */
@@ -105,10 +70,38 @@
exit(0);
}
+static int counter = 0;
-
static void test_keyhandler(const int key)
{
- fprintf(stderr, "key: %c\n", (char)key);
if (key == KEY_ESCAPE) finish(0);
+
+ if (key == KEY_RESIZE) {
+ endwin();
+ curs_set(0); /* Hide the cursor */
+
+ clear();
+ refresh();
+ text_window_resize();
+ }
+
+ if (key == KEY_DOWN) {
+ counter++;
+ if (counter == 1) {
+ text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
+ }
+
+ if (counter == 2) {
+ 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");
+ }
+
+ if (counter == 3) {
+ 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");
+ }
+
+ if (counter == 4) {
+ text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
+ counter = 1;
+ }
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sch...@us...> - 2008-11-22 01:38:43
|
Revision: 45
http://deraciel.svn.sourceforge.net/deraciel/?rev=45&view=rev
Author: schnippi001
Date: 2008-11-22 01:35:25 +0000 (Sat, 22 Nov 2008)
Log Message:
-----------
Added keyboard handler source files
Modified Paths:
--------------
trunk/main.c
Added Paths:
-----------
trunk/keyboard.c
trunk/keyboard.h
Added: trunk/keyboard.c
===================================================================
--- trunk/keyboard.c (rev 0)
+++ trunk/keyboard.c 2008-11-22 01:35:25 UTC (rev 45)
@@ -0,0 +1,50 @@
+#include "keyboard.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <ncurses.h>
+#include <pthread.h>
+
+
+pthread_t keyreader_thread;
+static void (*handler_cb)(const int key);
+
+
+
+static void *keyreader(void *unused)
+{
+ int tid;
+ int ch;
+
+ while(1) {
+ ch = getch();
+ if (handler_cb) handler_cb(ch);
+ }
+}
+
+
+
+void keyreader_create()
+{
+ int rc = pthread_create(&keyreader_thread, NULL, keyreader, NULL);
+ if (rc){
+ printf("ERROR; return code from pthread_create() is %d\n", rc);
+ exit(-1);
+ }
+}
+
+
+
+void keyreader_destroy()
+{
+}
+
+
+
+void keyreader_set_handler(void(*cb)(const int key))
+{
+ // TODO: Error handling
+ if (cb) {
+ handler_cb = cb;
+ }
+}
Property changes on: trunk/keyboard.c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/keyboard.h
===================================================================
--- trunk/keyboard.h (rev 0)
+++ trunk/keyboard.h 2008-11-22 01:35:25 UTC (rev 45)
@@ -0,0 +1,12 @@
+#ifndef DERACIEL_KEYBOARD_H
+#define DERACIEL_KEYBOARD_H
+
+#include <stdint.h>
+
+void keyreader_create(void);
+
+void keyreader_destroy(void);
+
+void keyreader_set_handler(void(*cb)(const int key));
+
+#endif // !DERACIEL_KEYBOARD_H
Property changes on: trunk/keyboard.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Modified: trunk/main.c
===================================================================
--- trunk/main.c 2008-11-22 01:19:43 UTC (rev 44)
+++ trunk/main.c 2008-11-22 01:35:25 UTC (rev 45)
@@ -17,6 +17,8 @@
#define KEY_ESCAPE 27
+static void test_keyhandler(const int key);
+
int main(int argc, char **argv)
{
signal(SIGINT, finish); /* arrange interrupts to terminate */
@@ -78,6 +80,8 @@
// refresh();
// }
+ keyreader_set_handler(test_keyhandler);
+
/* Let thread work */
while(1);
@@ -100,3 +104,11 @@
exit(0);
}
+
+
+
+static void test_keyhandler(const int key)
+{
+ fprintf(stderr, "key: %c\n", (char)key);
+ if (key == KEY_ESCAPE) finish(0);
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <lor...@us...> - 2008-11-22 01:19:47
|
Revision: 44
http://deraciel.svn.sourceforge.net/deraciel/?rev=44&view=rev
Author: lordhoto
Date: 2008-11-22 01:19:43 +0000 (Sat, 22 Nov 2008)
Log Message:
-----------
- Formatting
- Added stubs for proper object name support
Modified Paths:
--------------
trunk/char.h
trunk/inventory.c
trunk/inventory.h
trunk/obj_types.c
trunk/obj_types.h
trunk/object.c
trunk/object.h
Modified: trunk/char.h
===================================================================
--- trunk/char.h 2008-11-22 01:17:08 UTC (rev 43)
+++ trunk/char.h 2008-11-22 01:19:43 UTC (rev 44)
@@ -5,7 +5,8 @@
#include "inventory.h"
-enum stats {
+enum
+{
STAT_STRENGTH,
STAT_DEXTERITY,
STAT_WISDOM,
@@ -15,7 +16,8 @@
STAT_MAX_STATS
};
-struct char_struct {
+struct char_struct
+{
char name[32];
uint8_t stats[STAT_MAX_STATS];
Modified: trunk/inventory.c
===================================================================
--- trunk/inventory.c 2008-11-22 01:17:08 UTC (rev 43)
+++ trunk/inventory.c 2008-11-22 01:19:43 UTC (rev 44)
@@ -1,16 +1,16 @@
#include "inventory.h"
-void invt_init(struct invt_struct *inventory) {
- obj_init(OBJ_DESC_COINS, &inventory->coins);
-
- for (int i = 0; i < MAX_INVENTORY_OBJECTS; ++i)
- obj_init(OBJ_DESC_INVALID, inventory->objects + i);
+void invt_init(struct invt_struct *inventory)
+{
+ memset(inventory, 0, sizeof(struct invt_struct));
+
+ inventory->coins = obj_init(OBJ_DESC_COINS);
}
void invt_uninit(struct invt_struct *inventory) {
- obj_uninit(&inventory->coins);
+ obj_uninit(inventory->coins);
for (int i = 0; i < MAX_INVENTORY_OBJECTS; ++i)
- obj_uninit(inventory->objects + i);
+ obj_uninit(inventory->objects[i]);
}
Modified: trunk/inventory.h
===================================================================
--- trunk/inventory.h 2008-11-22 01:17:08 UTC (rev 43)
+++ trunk/inventory.h 2008-11-22 01:19:43 UTC (rev 44)
@@ -5,10 +5,11 @@
#define MAX_INVENTORY_OBJECTS 26
-struct invt_struct {
- struct obj_struct coins;
+struct invt_struct
+{
+ struct obj_struct *coins;
- struct obj_struct objects[MAX_INVENTORY_OBJECTS];
+ struct obj_struct *objects[MAX_INVENTORY_OBJECTS];
};
void invt_init(struct invt_struct *inventory);
Modified: trunk/obj_types.c
===================================================================
--- trunk/obj_types.c 2008-11-22 01:17:08 UTC (rev 43)
+++ trunk/obj_types.c 2008-11-22 01:19:43 UTC (rev 44)
@@ -1,20 +1,24 @@
#include "obj_types.h"
+#include "object.h"
// Gold piles always contain 0 coins by default
static const uint32_t coins_default_value = 0;
#define DEFINE_OBJ(ID, d, s) { ID, false, d, s }
-static struct obj_desc_struct obj_descs[] = {
+static struct obj_desc_struct obj_descs[] =
+{
DEFINE_OBJ(OBJ_DESC_COINS, &coins_default_value, sizeof(coins_default_value)),
DEFINE_OBJ(OBJ_DESC_INVALID, NULL, 0)
};
-const struct obj_desc_struct *obj_desc_find(obj_descriptor_id id) {
+const struct obj_desc_struct *obj_desc_find(obj_descriptor_id id)
+{
if (id == OBJ_DESC_INVALID)
return NULL;
- for (int i = 0; obj_descs[i].id != OBJ_DESC_INVALID; ++i) {
+ for (int i = 0; obj_descs[i].id != OBJ_DESC_INVALID; ++i)
+ {
if (obj_descs[i].id == id)
return obj_descs + i;
}
@@ -22,20 +26,26 @@
return NULL;
}
-bool obj_desc_is_identified(obj_descriptor_id id) {
+bool obj_desc_is_identified(obj_descriptor_id id)
+{
const struct obj_desc_struct *desc = obj_desc_find(id);
if (desc)
return desc->is_identified;
return false;
}
-void obj_desc_mark_identified(obj_descriptor_id id) {
+void obj_desc_mark_identified(obj_descriptor_id id)
+{
struct obj_desc_struct *desc = (struct obj_desc_struct *)obj_desc_find(id);
if (desc)
+ {
desc->is_identified = true;
+ obj_update_names(id);
+ }
}
-const char *obj_desc_get_name(obj_descriptor_id id) {
+const char *obj_desc_get_name(obj_descriptor_id id)
+{
// TODO
return "";
}
Modified: trunk/obj_types.h
===================================================================
--- trunk/obj_types.h 2008-11-22 01:17:08 UTC (rev 43)
+++ trunk/obj_types.h 2008-11-22 01:19:43 UTC (rev 44)
@@ -13,7 +13,8 @@
/**
* Different object types we have
*/
-enum {
+enum
+{
/**
* Object type for coins.
*
@@ -22,7 +23,8 @@
OBJ_DESC_COINS
};
-struct obj_desc_struct {
+struct obj_desc_struct
+{
obj_descriptor_id id;
bool is_identified;
Modified: trunk/object.c
===================================================================
--- trunk/object.c 2008-11-22 01:17:08 UTC (rev 43)
+++ trunk/object.c 2008-11-22 01:19:43 UTC (rev 44)
@@ -3,7 +3,12 @@
#include <string.h>
-void obj_init(obj_descriptor_id id, struct obj_struct *obj) {
+struct obj_struct *obj_init(obj_descriptor_id id)
+{
+ struct obj_struct *obj;
+ mem_alloc(struct obj_struct, obj);
+ // TODO: need to put obj into a global object list
+
obj->id = id;
strncpy(obj->name, obj_desc_get_name(id), sizeof(obj->name));
@@ -12,18 +17,28 @@
memset(obj->user_name, 0, sizeof(obj->user_name));
const struct obj_desc_struct *obj_desc = obj_desc_find(id);
- if (obj_desc) {
+ if (obj_desc)
+ {
mem_alloc_size(obj_desc->default_data_size, void, obj->user_data);
memcpy(obj->user_data, obj_desc->default_data, obj_desc->default_data_size);
- } else {
+ }
+ else
+ {
obj->user_data = NULL;
}
+
+ return obj;
}
-void obj_uninit(struct obj_struct *obj) {
- obj->id = OBJ_DESC_INVALID;
- memset(obj->name, 0, sizeof(obj->name));
-
+void obj_uninit(struct obj_struct *obj)
+{
mem_dealloc(obj->user_data);
+ // TODO: remove obj from global object list
+ mem_dealloc(obj);
}
+void obj_update_names(obj_descriptor_id id)
+{
+ // TODO: implemt via global object list
+}
+
Modified: trunk/object.h
===================================================================
--- trunk/object.h 2008-11-22 01:17:08 UTC (rev 43)
+++ trunk/object.h 2008-11-22 01:19:43 UTC (rev 44)
@@ -7,7 +7,8 @@
#define OBJ_NAME_LENGTH 64
-struct obj_struct {
+struct obj_struct
+{
obj_descriptor_id id;
char name[OBJ_NAME_LENGTH];
char user_name[OBJ_NAME_LENGTH];
@@ -15,9 +16,14 @@
void *user_data;
};
-void obj_init(obj_descriptor_id id, struct obj_struct *obj);
+struct obj_struct *obj_init(obj_descriptor_id id);
void obj_uninit(struct obj_struct *obj);
+// id == OBJ_DESC_INVALID would update all object names
+// TODO: define if all unidentified objects would get
+// new random names then too
+void obj_update_names(obj_descriptor_id id);
+
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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.
|
|
From: <lor...@us...> - 2008-11-22 01:05:40
|
Revision: 42
http://deraciel.svn.sourceforge.net/deraciel/?rev=42&view=rev
Author: lordhoto
Date: 2008-11-22 01:05:36 +0000 (Sat, 22 Nov 2008)
Log Message:
-----------
Added stubs for object naming.
Modified Paths:
--------------
trunk/obj_types.c
trunk/obj_types.h
trunk/object.c
trunk/object.h
Modified: trunk/obj_types.c
===================================================================
--- trunk/obj_types.c 2008-11-22 00:53:40 UTC (rev 41)
+++ trunk/obj_types.c 2008-11-22 01:05:36 UTC (rev 42)
@@ -35,3 +35,8 @@
desc->is_identified = true;
}
+const char *obj_desc_get_name(obj_descriptor_id id) {
+ // TODO
+ return "";
+}
+
Modified: trunk/obj_types.h
===================================================================
--- trunk/obj_types.h 2008-11-22 00:53:40 UTC (rev 41)
+++ trunk/obj_types.h 2008-11-22 01:05:36 UTC (rev 42)
@@ -37,5 +37,7 @@
void obj_desc_mark_identified(obj_descriptor_id id);
+const char *obj_desc_get_name(obj_descriptor_id id);
+
#endif
Modified: trunk/object.c
===================================================================
--- trunk/object.c 2008-11-22 00:53:40 UTC (rev 41)
+++ trunk/object.c 2008-11-22 01:05:36 UTC (rev 42)
@@ -5,8 +5,12 @@
void obj_init(obj_descriptor_id id, struct obj_struct *obj) {
obj->id = id;
- memset(obj->name, 0, sizeof(obj->name));
+ strncpy(obj->name, obj_desc_get_name(id), sizeof(obj->name));
+ obj->name[sizeof(obj->name)-1] = 0;
+
+ memset(obj->user_name, 0, sizeof(obj->user_name));
+
const struct obj_desc_struct *obj_desc = obj_desc_find(id);
if (obj_desc) {
mem_alloc_size(obj_desc->default_data_size, void, obj->user_data);
Modified: trunk/object.h
===================================================================
--- trunk/object.h 2008-11-22 00:53:40 UTC (rev 41)
+++ trunk/object.h 2008-11-22 01:05:36 UTC (rev 42)
@@ -10,6 +10,7 @@
struct obj_struct {
obj_descriptor_id id;
char name[OBJ_NAME_LENGTH];
+ char user_name[OBJ_NAME_LENGTH];
void *user_data;
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <lor...@us...> - 2008-11-22 00:53:45
|
Revision: 41
http://deraciel.svn.sourceforge.net/deraciel/?rev=41&view=rev
Author: lordhoto
Date: 2008-11-22 00:53:40 +0000 (Sat, 22 Nov 2008)
Log Message:
-----------
Added identified flag to obj descriptors.
Modified Paths:
--------------
trunk/obj_types.c
trunk/obj_types.h
trunk/object.h
trunk/util.h
Modified: trunk/obj_types.c
===================================================================
--- trunk/obj_types.c 2008-11-22 00:39:38 UTC (rev 40)
+++ trunk/obj_types.c 2008-11-22 00:53:40 UTC (rev 41)
@@ -3,9 +3,11 @@
// Gold piles always contain 0 coins by default
static const uint32_t coins_default_value = 0;
-static const struct obj_desc_struct obj_descs[] = {
- { OBJ_DESC_COINS, &coins_default_value, sizeof(coins_default_value) },
- { OBJ_DESC_INVALID, NULL, 0 }
+#define DEFINE_OBJ(ID, d, s) { ID, false, d, s }
+
+static struct obj_desc_struct obj_descs[] = {
+ DEFINE_OBJ(OBJ_DESC_COINS, &coins_default_value, sizeof(coins_default_value)),
+ DEFINE_OBJ(OBJ_DESC_INVALID, NULL, 0)
};
const struct obj_desc_struct *obj_desc_find(obj_descriptor_id id) {
@@ -20,3 +22,16 @@
return NULL;
}
+bool obj_desc_is_identified(obj_descriptor_id id) {
+ const struct obj_desc_struct *desc = obj_desc_find(id);
+ if (desc)
+ return desc->is_identified;
+ return false;
+}
+
+void obj_desc_mark_identified(obj_descriptor_id id) {
+ struct obj_desc_struct *desc = (struct obj_desc_struct *)obj_desc_find(id);
+ if (desc)
+ desc->is_identified = true;
+}
+
Modified: trunk/obj_types.h
===================================================================
--- trunk/obj_types.h 2008-11-22 00:39:38 UTC (rev 40)
+++ trunk/obj_types.h 2008-11-22 00:53:40 UTC (rev 41)
@@ -1,6 +1,8 @@
#ifndef DERACIEL_OBJ_TYPES_H
#define DERACIEL_OBJ_TYPES_H
+#include "util.h"
+
#include <stdint.h>
#include <string.h>
@@ -8,14 +10,14 @@
#define OBJ_DESC_INVALID ((obj_descriptor_id)-1)
-/*
+/**
* Different object types we have
*/
enum {
- /*
+ /**
* Object type for coins.
*
- * [default_data] = uint32_t
+ * [default_data] = uint32_t => indicating how many gold coins there are
*/
OBJ_DESC_COINS
};
@@ -23,11 +25,17 @@
struct obj_desc_struct {
obj_descriptor_id id;
+ bool is_identified;
+
const void *default_data;
size_t default_data_size;
};
const struct obj_desc_struct *obj_desc_find(obj_descriptor_id id);
+bool obj_desc_is_identified(obj_descriptor_id id);
+
+void obj_desc_mark_identified(obj_descriptor_id id);
+
#endif
Modified: trunk/object.h
===================================================================
--- trunk/object.h 2008-11-22 00:39:38 UTC (rev 40)
+++ trunk/object.h 2008-11-22 00:53:40 UTC (rev 41)
@@ -19,3 +19,4 @@
void obj_uninit(struct obj_struct *obj);
#endif
+
Modified: trunk/util.h
===================================================================
--- trunk/util.h 2008-11-22 00:39:38 UTC (rev 40)
+++ trunk/util.h 2008-11-22 00:53:40 UTC (rev 41)
@@ -24,5 +24,17 @@
#define mem_dealloc(var) free(var)
+#ifndef bool
+#define bool unsigned char
+#endif // !bool
+
+#ifndef true
+#define true 1
+#endif // !true
+
+#ifndef false
+#define false 0
+#endif // !false
+
#endif // !DERACIEL_UTIL_H
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <lor...@us...> - 2008-11-22 00:39:42
|
Revision: 40
http://deraciel.svn.sourceforge.net/deraciel/?rev=40&view=rev
Author: lordhoto
Date: 2008-11-22 00:39:38 +0000 (Sat, 22 Nov 2008)
Log Message:
-----------
Added primiliary object, inventory and character structs.
Modified Paths:
--------------
trunk/INSTALL
trunk/util.h
Added Paths:
-----------
trunk/char.h
trunk/inventory.c
trunk/inventory.h
trunk/obj_types.c
trunk/obj_types.h
trunk/object.c
trunk/object.h
Modified: trunk/INSTALL
===================================================================
--- trunk/INSTALL 2008-11-21 23:10:39 UTC (rev 39)
+++ trunk/INSTALL 2008-11-22 00:39:38 UTC (rev 40)
@@ -1,7 +1,7 @@
Compile
=======
-clear && gcc -std=c99 -o main main.c text_window.c random.c -lncurses -lform
+clear && gcc -std=c99 -o main *.c -lncurses -lform
Run
Added: trunk/char.h
===================================================================
--- trunk/char.h (rev 0)
+++ trunk/char.h 2008-11-22 00:39:38 UTC (rev 40)
@@ -0,0 +1,30 @@
+#ifndef DERACIEL_CHAR_H
+#define DERACIEL_CHAR_H
+
+#include <stdint.h>
+
+#include "inventory.h"
+
+enum stats {
+ STAT_STRENGTH,
+ STAT_DEXTERITY,
+ STAT_WISDOM,
+ STAT_WILLPOWER,
+ STAT_CONSTITUTION,
+ STAT_CHARISMA,
+ STAT_MAX_STATS
+};
+
+struct char_struct {
+ char name[32];
+
+ uint8_t stats[STAT_MAX_STATS];
+
+ uint32_t experience;
+ uint8_t level;
+
+ struct invt_struct inventory;
+};
+
+#endif
+
Property changes on: trunk/char.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/inventory.c
===================================================================
--- trunk/inventory.c (rev 0)
+++ trunk/inventory.c 2008-11-22 00:39:38 UTC (rev 40)
@@ -0,0 +1,16 @@
+#include "inventory.h"
+
+void invt_init(struct invt_struct *inventory) {
+ obj_init(OBJ_DESC_COINS, &inventory->coins);
+
+ for (int i = 0; i < MAX_INVENTORY_OBJECTS; ++i)
+ obj_init(OBJ_DESC_INVALID, inventory->objects + i);
+}
+
+void invt_uninit(struct invt_struct *inventory) {
+ obj_uninit(&inventory->coins);
+
+ for (int i = 0; i < MAX_INVENTORY_OBJECTS; ++i)
+ obj_uninit(inventory->objects + i);
+}
+
Property changes on: trunk/inventory.c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/inventory.h
===================================================================
--- trunk/inventory.h (rev 0)
+++ trunk/inventory.h 2008-11-22 00:39:38 UTC (rev 40)
@@ -0,0 +1,18 @@
+#ifndef DERACIEL_INVENTORY_H
+#define DERACIEL_INVENTORY_H
+
+#include "object.h"
+
+#define MAX_INVENTORY_OBJECTS 26
+
+struct invt_struct {
+ struct obj_struct coins;
+
+ struct obj_struct objects[MAX_INVENTORY_OBJECTS];
+};
+
+void invt_init(struct invt_struct *inventory);
+
+void invt_uninit(struct invt_struct *inventory);
+
+#endif
Property changes on: trunk/inventory.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/obj_types.c
===================================================================
--- trunk/obj_types.c (rev 0)
+++ trunk/obj_types.c 2008-11-22 00:39:38 UTC (rev 40)
@@ -0,0 +1,22 @@
+#include "obj_types.h"
+
+// Gold piles always contain 0 coins by default
+static const uint32_t coins_default_value = 0;
+
+static const struct obj_desc_struct obj_descs[] = {
+ { OBJ_DESC_COINS, &coins_default_value, sizeof(coins_default_value) },
+ { OBJ_DESC_INVALID, NULL, 0 }
+};
+
+const struct obj_desc_struct *obj_desc_find(obj_descriptor_id id) {
+ if (id == OBJ_DESC_INVALID)
+ return NULL;
+
+ for (int i = 0; obj_descs[i].id != OBJ_DESC_INVALID; ++i) {
+ if (obj_descs[i].id == id)
+ return obj_descs + i;
+ }
+
+ return NULL;
+}
+
Property changes on: trunk/obj_types.c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/obj_types.h
===================================================================
--- trunk/obj_types.h (rev 0)
+++ trunk/obj_types.h 2008-11-22 00:39:38 UTC (rev 40)
@@ -0,0 +1,33 @@
+#ifndef DERACIEL_OBJ_TYPES_H
+#define DERACIEL_OBJ_TYPES_H
+
+#include <stdint.h>
+#include <string.h>
+
+typedef uint32_t obj_descriptor_id;
+
+#define OBJ_DESC_INVALID ((obj_descriptor_id)-1)
+
+/*
+ * Different object types we have
+ */
+enum {
+ /*
+ * Object type for coins.
+ *
+ * [default_data] = uint32_t
+ */
+ OBJ_DESC_COINS
+};
+
+struct obj_desc_struct {
+ obj_descriptor_id id;
+
+ const void *default_data;
+ size_t default_data_size;
+};
+
+const struct obj_desc_struct *obj_desc_find(obj_descriptor_id id);
+
+#endif
+
Property changes on: trunk/obj_types.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/object.c
===================================================================
--- trunk/object.c (rev 0)
+++ trunk/object.c 2008-11-22 00:39:38 UTC (rev 40)
@@ -0,0 +1,25 @@
+#include "object.h"
+#include "util.h"
+
+#include <string.h>
+
+void obj_init(obj_descriptor_id id, struct obj_struct *obj) {
+ obj->id = id;
+ memset(obj->name, 0, sizeof(obj->name));
+
+ const struct obj_desc_struct *obj_desc = obj_desc_find(id);
+ if (obj_desc) {
+ mem_alloc_size(obj_desc->default_data_size, void, obj->user_data);
+ memcpy(obj->user_data, obj_desc->default_data, obj_desc->default_data_size);
+ } else {
+ obj->user_data = NULL;
+ }
+}
+
+void obj_uninit(struct obj_struct *obj) {
+ obj->id = OBJ_DESC_INVALID;
+ memset(obj->name, 0, sizeof(obj->name));
+
+ mem_dealloc(obj->user_data);
+}
+
Property changes on: trunk/object.c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: trunk/object.h
===================================================================
--- trunk/object.h (rev 0)
+++ trunk/object.h 2008-11-22 00:39:38 UTC (rev 40)
@@ -0,0 +1,21 @@
+#ifndef DERACIEL_OBJECT_H
+#define DERACIEL_OBJECT_H
+
+#include "obj_types.h"
+
+#include <stdint.h>
+
+#define OBJ_NAME_LENGTH 64
+
+struct obj_struct {
+ obj_descriptor_id id;
+ char name[OBJ_NAME_LENGTH];
+
+ void *user_data;
+};
+
+void obj_init(obj_descriptor_id id, struct obj_struct *obj);
+
+void obj_uninit(struct obj_struct *obj);
+
+#endif
Property changes on: trunk/object.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Modified: trunk/util.h
===================================================================
--- trunk/util.h 2008-11-21 23:10:39 UTC (rev 39)
+++ trunk/util.h 2008-11-22 00:39:38 UTC (rev 40)
@@ -13,6 +13,15 @@
} \
} while (0)
+#define mem_alloc_size(size, type, var) \
+ do { \
+ var = (type*)malloc(size); \
+ if (!var) { \
+ fprintf(stderr, "Couldn't allocate memory for var %s of size %d in file %s line %d\n", #var, (int)size, __FILE__, __LINE__); \
+ exit(-1); \
+ } \
+ } while (0)
+
#define mem_dealloc(var) free(var)
#endif // !DERACIEL_UTIL_H
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sch...@us...> - 2008-11-21 23:10:54
|
Revision: 39
http://deraciel.svn.sourceforge.net/deraciel/?rev=39&view=rev
Author: schnippi001
Date: 2008-11-21 23:10:39 +0000 (Fri, 21 Nov 2008)
Log Message:
-----------
Properly multiline output resize
Modified Paths:
--------------
trunk/text_window.c
Modified: trunk/text_window.c
===================================================================
--- trunk/text_window.c 2008-11-21 22:59:49 UTC (rev 38)
+++ trunk/text_window.c 2008-11-21 23:10:39 UTC (rev 39)
@@ -102,6 +102,9 @@
wclear(border_wnd);
wclear(text_wnd);
+ clear();
+ refresh();
+
#ifdef TEXTWINDOW_BORDER
/* Redraw border with new dimensions */
draw_border();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sch...@us...> - 2008-11-21 22:59:57
|
Revision: 38
http://deraciel.svn.sourceforge.net/deraciel/?rev=38&view=rev
Author: schnippi001
Date: 2008-11-21 22:59:49 +0000 (Fri, 21 Nov 2008)
Log Message:
-----------
Multiline output, first
Modified Paths:
--------------
trunk/main.c
trunk/text_window.c
Modified: trunk/main.c
===================================================================
--- trunk/main.c 2008-11-21 20:44:23 UTC (rev 37)
+++ trunk/main.c 2008-11-21 22:59:49 UTC (rev 38)
@@ -28,8 +28,8 @@
curs_set(0); /* Hide the cursor */
start_color();
- init_pair(1, COLOR_BLUE, COLOR_BLACK);
- init_pair(2, COLOR_YELLOW, COLOR_RED);
+ init_pair(1, COLOR_WHITE, COLOR_BLUE);
+ init_pair(2, COLOR_BLACK, COLOR_YELLOW);
clear();
refresh();
@@ -38,8 +38,25 @@
text_window_create();
- text_window_out("Deraciel v0.1");
+ // 1 Line output
+ text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
+ 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){
Modified: trunk/text_window.c
===================================================================
--- trunk/text_window.c 2008-11-21 20:44:23 UTC (rev 37)
+++ trunk/text_window.c 2008-11-21 22:59:49 UTC (rev 38)
@@ -3,81 +3,113 @@
#include <string.h>
#include <form.h>
-#define TEXTWND_MAXWIDTH (80)
-#define TEXTWND_MAXHEIGHT (2)
-#define TEXTWND_LINEBUFFER_SIZE 256
-#define TEXTWND_BORDER
+#define BORDER_WND_MAXWIDTH (80)
+#define BORDER_WND_MAXHEIGHT (2)
+#define TEXTWINDOW_LINEBUFFER_SIZE (3*78 + 1) // 3 lines * 78 characters + '\n'
+#define TEXTWINDOW_BORDER
-static WINDOW *TEXTWND; /* Window handle */
-static char linebuffer[TEXTWND_LINEBUFFER_SIZE];
+static WINDOW *border_wnd; /* Window handle */
+static WINDOW *text_wnd; /* Window handle */
+static char linebuffer[TEXTWINDOW_LINEBUFFER_SIZE];
-static void text_window_repaint(void);
+static void repaint(void);
+static void draw_border();
-
void text_window_create(void)
{
- TEXTWND = newwin(TEXTWND_MAXHEIGHT, TEXTWND_MAXWIDTH, 0, 0);
+ border_wnd = newwin(BORDER_WND_MAXHEIGHT, BORDER_WND_MAXWIDTH, 0, 0);
+ text_wnd = newwin(BORDER_WND_MAXHEIGHT-1, BORDER_WND_MAXWIDTH-2, 0, 1);
- if (!TEXTWND) {
+ if (!border_wnd || !text_wnd) {
fprintf(stderr, "text window creation failed!\n");
return;
}
- wborder(TEXTWND, 0, 0, ' ', 0, ACS_VLINE, ACS_VLINE, '\\', '/');
+ wattron(border_wnd, COLOR_PAIR(1));
+ wbkgd(text_wnd, COLOR_PAIR(2));
- wrefresh(TEXTWND);
+
+ draw_border();
+
+ wrefresh(border_wnd);
+ wrefresh(text_wnd);
}
void text_window_destroy()
{
- if (TEXTWND) {
+ if (border_wnd) {
/* Clear window from screen */
- wclear(TEXTWND);
- wrefresh(TEXTWND);
+ wclear(border_wnd);
+ wrefresh(border_wnd);
/* Free resources consumed by the window */
- delwin(TEXTWND);
- TEXTWND = NULL;
+ delwin(text_wnd);
+ text_wnd = NULL;
+
+ delwin(border_wnd);
+ border_wnd = NULL;
}
}
-void text_window_repaint()
+
+
+void text_window_resize(void)
{
/* Clear window from screen */
- wclear(TEXTWND);
+ wclear(border_wnd);
+ wclear(text_wnd);
-#ifdef TEXTWND_BORDER
- /* Redraw border with new dimensions */
- wborder(TEXTWND, 0, 0, ' ', 0, ACS_VLINE, ACS_VLINE, '\\', '/');
-#endif // TEXTWND_BORDER
+ /* Reallocate storage for resized text window */
+ wresize(border_wnd, BORDER_WND_MAXHEIGHT, BORDER_WND_MAXWIDTH);
+ wresize(text_wnd, BORDER_WND_MAXHEIGHT-1, BORDER_WND_MAXWIDTH-2);
- wmove(TEXTWND, 0, 1);
- wprintw(TEXTWND, linebuffer);
- wrefresh(TEXTWND);
+ repaint();
}
-void text_window_resize(void)
+
+
+void text_window_out(const char *string)
{
- /* Clear window from screen */
- wclear(TEXTWND);
+ strncpy(linebuffer, string, TEXTWINDOW_LINEBUFFER_SIZE);
+ linebuffer[TEXTWINDOW_LINEBUFFER_SIZE-1] = '\0';
- if (TEXTWND) {
- /* Reallocate storage for resized text window */
- wresize(TEXTWND, TEXTWND_MAXHEIGHT, TEXTWND_MAXWIDTH);
- }
+ // 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);
- text_window_repaint();
+ int lines = (mod == 0 ? 0 : 1) + strlen(linebuffer)/(BORDER_WND_MAXWIDTH-2);
+
+ wresize(text_wnd, lines, BORDER_WND_MAXWIDTH-2);
+ wresize(border_wnd, lines+1, BORDER_WND_MAXWIDTH);
+
+ repaint();
}
-void text_window_out(const char *string)
+void draw_border()
{
- strncpy(linebuffer, string, TEXTWND_LINEBUFFER_SIZE);
- linebuffer[TEXTWND_LINEBUFFER_SIZE-1] = '\0';
- text_window_repaint();
+ wborder(border_wnd, 0, 0, ' ', 0, ACS_VLINE, ACS_VLINE, '\\', '/');
}
+
+
+void repaint()
+{
+ /* Clear window from screen */
+ wclear(border_wnd);
+ wclear(text_wnd);
+
+#ifdef TEXTWINDOW_BORDER
+ /* Redraw border with new dimensions */
+ draw_border();
+#endif // TEXTWINDOW_BORDER
+
+ wmove(text_wnd, 0, 0);
+ wprintw(text_wnd, linebuffer);
+
+ wrefresh(border_wnd);
+ wrefresh(text_wnd);
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|