From c0f596e0269bfd114b4ff98c2d7d2855d88e6ef5 Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Fri, 22 Aug 2008 13:03:44 -0400 Subject: [PATCH 01/16] fixed addition of well at start --- src/effectManager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/effectManager.cpp b/src/effectManager.cpp index c59decc..a75e5d8 100644 --- a/src/effectManager.cpp +++ b/src/effectManager.cpp @@ -39,11 +39,10 @@ GravityWell* mouseWell; void effect::init() { - mouseWell = new GravityWell(input::mousePosition()); + mouseWell = new GravityWell(Vector2(0,0)); active_Effects.insert(new Screen()); active_Effects.insert(new Gravity()); - active_Effects.insert(mouseWell); } void effect::clean() { -- 2.10.2 From 87c9b12ffbcb8458c7e031045d34d2a1de5ea78a Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Fri, 22 Aug 2008 13:40:38 -0400 Subject: [PATCH 02/16] wip: config reader --- configs/test.cfg | 1 + src/config/config.cpp | 3 +++ src/config/reader.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/config/reader.h | 31 ++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 configs/test.cfg create mode 100644 src/config/reader.cpp create mode 100644 src/config/reader.h diff --git a/configs/test.cfg b/configs/test.cfg new file mode 100644 index 0000000..e965047 --- /dev/null +++ b/configs/test.cfg @@ -0,0 +1 @@ +Hello diff --git a/src/config/config.cpp b/src/config/config.cpp index 35efe4f..9aa6f86 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -16,6 +16,8 @@ */ #include "config.h" + +#include "reader.h" #include "../input/inputManager.h" /// ***** Private Method Headers ***** @@ -25,6 +27,7 @@ void cfg::init() { + readConfigs(NULL); // TODO read in config files } void cfg::clean() diff --git a/src/config/reader.cpp b/src/config/reader.cpp new file mode 100644 index 0000000..ce35ab8 --- /dev/null +++ b/src/config/reader.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "reader.h" +#include "../debug.h" + +#include +#include +#include + +using std::ifstream; +using std::string; + +char* configDir = "../configs/"; + +/// ***** Private Method Headers ***** + +void processLine(const string& str, keyMap* map); + +/// ***** Private Variables ***** + +/// ***** Public Methods ***** + +void readConfigs(keyMap* map) +{ + char fileName[64]; + + strcpy(fileName, configDir); + strcat(fileName, "test.cfg"); + + ifstream file(fileName); + + if( !file.is_open() ) + { + cerr << "Unable to open file " << fileName << "." << endl; + exit(1); + } + + while(true) + { + string line; + getline(file, line); + + if(file.eof()) + break; + + processLine(line, map); + } + + file.close(); +} + +/// ***** Private Methods ***** + +void processLine(const string& str, keyMap* map) +{ + cout << str << endl; +} diff --git a/src/config/reader.h b/src/config/reader.h new file mode 100644 index 0000000..672b6da --- /dev/null +++ b/src/config/reader.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#ifndef READER_H +#define READER_H + +#include +#include + +typedef std::map keyMap; + +/// ***** Header Methods ***** + +void readConfigs(keyMap*); + +#endif // READER_H -- 2.10.2 From 07df2aea152374f1d2be55bfa0a05ba55fc1a112 Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Fri, 22 Aug 2008 15:29:54 -0400 Subject: [PATCH 03/16] wip: config reader, reading input --- configs/test.cfg | 34 ++++++++++++++++ src/config/reader.cpp | 106 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 139 insertions(+), 1 deletion(-) diff --git a/configs/test.cfg b/configs/test.cfg index e965047..c4d7b7f 100644 --- a/configs/test.cfg +++ b/configs/test.cfg @@ -1 +1,35 @@ Hello + +roger=flag0000 +roger=flag0001 +roger= flag0010 +roger= flag0011 +roger =flag0100 +roger =flag0101 +roger = flag0110 +roger = flag0111 + roger=flag1000 + roger=flag1001 + roger= flag1010 + roger= flag1011 + roger =flag1100 + roger =flag1101 + roger = flag1110 + roger = flag1111 + +roger=flag0000 +roger=flag0002 +roger= flag0020 +roger= flag0022 +roger =flag0200 +roger =flag0202 +roger = flag0220 +roger = flag0222 + roger=flag2000 + roger=flag2002 + roger= flag2020 + roger= flag2022 + roger =flag2200 + roger =flag2202 + roger = flag2220 + roger = flag2222 diff --git a/src/config/reader.cpp b/src/config/reader.cpp index ce35ab8..de6da20 100644 --- a/src/config/reader.cpp +++ b/src/config/reader.cpp @@ -30,6 +30,7 @@ char* configDir = "../configs/"; /// ***** Private Method Headers ***** void processLine(const string& str, keyMap* map); +bool extractLine(const string& str, string* name, string* value); /// ***** Private Variables ***** @@ -68,5 +69,108 @@ void readConfigs(keyMap* map) void processLine(const string& str, keyMap* map) { - cout << str << endl; + string name; + string value; + + bool extracted; + + extracted = extractLine(str, &name, &value); + + if(extracted) + { + cout << name << endl; + cout << value << endl; + } +} + +/* + * Return true iff the string str, had a name and value extracted and saved in + * name and value. Otherwise return false and leave name and value alone. + */ +bool extractLine(const string& str, string* name, string* value) +{ + /* + * state := 0 if eating leading name whitespace + * := 1 if saving name + * := 2 if eating trailing name whitespace + * := 3 if eating leading value whitespace + * := 4 if saving value + * := 5 if all is done and well + */ + int state = 0; + + int char_pos = 0; + + int name_start; + int name_end; + + int value_start; + int value_end; + + const char* c_str = str.c_str(); + + while(true) + { + if(c_str[char_pos] == 0 && state != 4) + return false; + + switch (state) + { + case 0: + if(c_str[char_pos] != ' ' + && c_str[char_pos] != '\t') + { + state++; + name_start = char_pos; + } + break; + case 1: + if(c_str[char_pos] == ' ' + || c_str[char_pos] == '\t' + || c_str[char_pos] == '=') + { + state++; + name_end = char_pos; + } + if(c_str[char_pos] == '=') + char_pos--; // decrement to stay on this char + break; + case 2: + if(c_str[char_pos] == '=') + { + state++; + } + break; + case 3: + if(c_str[char_pos] != ' ' + && c_str[char_pos] != '\t') + { + state++; + value_start = char_pos; + } + break; + case 4: + if(c_str[char_pos] == ' ' + || c_str[char_pos] == '\t' + || c_str[char_pos] == 0) + { + state++; + value_end = char_pos; + } + break; + } + + if(state == 5) + break; + + char_pos++; + } + + name->clear(); + value->clear(); + + name->replace(0, 0, c_str, name_start, name_end-name_start); + value->replace(0, 0, c_str, value_start, value_end-value_start); + + return true; } -- 2.10.2 From 6d9186c57c41e5ec03356da142bc0fef71ce569f Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Fri, 22 Aug 2008 15:54:46 -0400 Subject: [PATCH 04/16] gravity well force moved to const --- src/Effects/GravityWell.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Effects/GravityWell.cpp b/src/Effects/GravityWell.cpp index e3ab469..581d628 100644 --- a/src/Effects/GravityWell.cpp +++ b/src/Effects/GravityWell.cpp @@ -18,6 +18,7 @@ #include "GravityWell.h" #include "../Entities/PhysicsEntity.h" +float wellGravity = 0.5; /// ***** Constructors/Destructors ***** @@ -44,7 +45,7 @@ Vector2 GravityWell::forceDelta(const PhysicsEntity* e, float) const Vector2 acc(0,0); if( sqrDist > 0.5F ) - acc += delta / sqrDist * mass / 2; + acc += delta / sqrDist * mass * wellGravity; return acc; } -- 2.10.2 From fcfc5f0d5aa02a8d06276ce73796298aa59b30aa Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Fri, 22 Aug 2008 17:48:57 -0400 Subject: [PATCH 05/16] template had missing ; for class ... lmao --- templates/template.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/template.h b/templates/template.h index 1e5f600..a2cf752 100644 --- a/templates/template.h +++ b/templates/template.h @@ -23,7 +23,7 @@ class temp { -} +}; /// ***** Header Methods ***** -- 2.10.2 From 9d049dcaf022e500e643d6e46bb29412aa419653 Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Fri, 22 Aug 2008 18:26:52 -0400 Subject: [PATCH 06/16] wip: reader, added key mappings --- src/config/reader.cpp | 115 +++++++++++++++++++++++++++++++++++++++++++++++--- src/config/reader.h | 7 ++- 2 files changed, 115 insertions(+), 7 deletions(-) diff --git a/src/config/reader.cpp b/src/config/reader.cpp index de6da20..2d1d677 100644 --- a/src/config/reader.cpp +++ b/src/config/reader.cpp @@ -25,18 +25,21 @@ using std::ifstream; using std::string; -char* configDir = "../configs/"; +typedef std::map kMap; +kMap keyMap; /// ***** Private Method Headers ***** -void processLine(const string& str, keyMap* map); +void processLine(const string& str, inputMap* map); bool extractLine(const string& str, string* name, string* value); /// ***** Private Variables ***** +char* configDir = "../configs/"; + /// ***** Public Methods ***** -void readConfigs(keyMap* map) +void readConfigs(inputMap* map) { char fileName[64]; @@ -67,7 +70,7 @@ void readConfigs(keyMap* map) /// ***** Private Methods ***** -void processLine(const string& str, keyMap* map) +void processLine(const string& str, inputMap* map) { string name; string value; @@ -78,6 +81,7 @@ void processLine(const string& str, keyMap* map) if(extracted) { + //map->insert(name, value); cout << name << endl; cout << value << endl; } @@ -132,13 +136,18 @@ bool extractLine(const string& str, string* name, string* value) state++; name_end = char_pos; } + if(c_str[char_pos] == '=') char_pos--; // decrement to stay on this char break; case 2: if(c_str[char_pos] == '=') - { state++; + + if(c_str[char_pos] != ' ' + && c_str[char_pos] != '\t') + { + return false; } break; case 3: @@ -174,3 +183,99 @@ bool extractLine(const string& str, string* name, string* value) return true; } + +bool extractKey(const string& str, Uint8* key) +{ +// if(str.length() != 1) +// return false; + + return false; +} + +void createKeyMap() +{ + // add all the letters + for (int i = 'A'; i <= 'Z'; i++) // uppercase + keyMap["" + (char)i] = (SDLKey)i; + for (int i = 'a'; i <= 'z'; i++) // lowercase + keyMap["" + (char)i] = (SDLKey)i; + + // add all the numbers + for (int i = '0'; i <= '9'; i++) + keyMap["" + (char)i] = (SDLKey)i; + + /* + // add the function keys + int F1 = (int)Key.F1; + for (int i = F1; i <= (int)Key.F15; i++) + { + keyMap.Add("F" + (i - F1 + 1), (Key)i); + keyMap.Add("f" + (i - F1 + 1), (Key)i); + } + */ + + keyMap["LCtrl"] = SDLK_LCTRL; + keyMap["LeftControl"] = SDLK_LCTRL; + keyMap["LAlt"] = SDLK_LALT; + keyMap["LeftAlt"] = SDLK_LALT; + keyMap["LShift"] = SDLK_LSHIFT; + keyMap["LeftShift"] = SDLK_LSHIFT; + keyMap["LWin"] = SDLK_LSUPER; + keyMap["LeftWindows"] = SDLK_LSUPER; + keyMap["LeftMeta"] = SDLK_LMETA; + keyMap["LMeta"] = SDLK_LMETA; + + keyMap["RCtrl"] = SDLK_RCTRL; + keyMap["RightControl"] = SDLK_RCTRL; + keyMap["RAlt"] = SDLK_RALT; + keyMap["RightAlt"] = SDLK_RALT; + keyMap["RShift"] = SDLK_RSHIFT; + keyMap["RightShift"] = SDLK_RSHIFT; + keyMap["RWin"] = SDLK_RSUPER; + keyMap["RightWindows"] = SDLK_RSUPER; + keyMap["RightMeta"] = SDLK_RMETA; + keyMap["RMeta"] = SDLK_RMETA; + + keyMap["Esc"] = SDLK_ESCAPE; + keyMap["Escape"] = SDLK_ESCAPE; + + keyMap["Return"] = SDLK_RETURN; + keyMap["Enter"] = SDLK_RETURN; + + keyMap["Insert"] = SDLK_INSERT; + keyMap["Home"] = SDLK_HOME; + keyMap["Delete"] = SDLK_DELETE; + keyMap["End"] = SDLK_END; + keyMap["PageUp"] = SDLK_PAGEUP; + keyMap["PageDown"] = SDLK_PAGEDOWN; + + keyMap["Minus"] = SDLK_MINUS; + keyMap["Equal"] = SDLK_EQUALS; + keyMap["Equals"] = SDLK_EQUALS; + keyMap["LeftBracket"] = SDLK_LEFTBRACKET; + keyMap["LBracket"] = SDLK_LEFTBRACKET; + keyMap["RightBracket"] = SDLK_RIGHTBRACKET; + keyMap["RBracket"] = SDLK_RIGHTBRACKET; + keyMap["Backslash"] = SDLK_BACKSLASH; + keyMap["Slash"] = SDLK_SLASH; + keyMap["Semicolon"] = SDLK_SEMICOLON; + keyMap["Semi"] = SDLK_SEMICOLON; + keyMap["Quote"] = SDLK_QUOTE; + keyMap["Comma"] = SDLK_COMMA; + keyMap["Period"] = SDLK_PERIOD; + keyMap["Space"] = SDLK_SPACE; + keyMap["BSpace"] = SDLK_BACKSPACE; + keyMap["Backspace"] = SDLK_BACKSPACE; + keyMap["BackSpace"] = SDLK_BACKSPACE; + + keyMap["Tab"] = SDLK_TAB; + keyMap["BackQuote"] = SDLK_BACKQUOTE; + keyMap["BQuote"] = SDLK_BACKQUOTE; + keyMap["CapsLock"] = SDLK_CAPSLOCK; + keyMap["Caps"] = SDLK_CAPSLOCK; + + keyMap["Up"] = SDLK_UP; + keyMap["Down"] = SDLK_DOWN; + keyMap["Left"] = SDLK_LEFT; + keyMap["Right"] = SDLK_RIGHT; +} diff --git a/src/config/reader.h b/src/config/reader.h index 672b6da..eb13cbc 100644 --- a/src/config/reader.h +++ b/src/config/reader.h @@ -21,11 +21,14 @@ #include #include +#include -typedef std::map keyMap; +using std::string; + +typedef std::map inputMap; /// ***** Header Methods ***** -void readConfigs(keyMap*); +void readConfigs(inputMap*); #endif // READER_H -- 2.10.2 From b26d04ae44735baadfd6e12a907c5bb1f249bd21 Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Thu, 28 Aug 2008 16:15:32 -0400 Subject: [PATCH 07/16] fixed relative config path, needs to be run from withen run_physics directory now --- src/Makefile | 2 +- src/config/reader.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Makefile b/src/Makefile index c9f8c86..13c255e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -139,7 +139,7 @@ tar: ../physics.tar.bz2 .PHONY: run run: all - ${TARGET} + cd ..; ./run_physics .PHONY: gdb gdb: all diff --git a/src/config/reader.cpp b/src/config/reader.cpp index 2d1d677..19f7d33 100644 --- a/src/config/reader.cpp +++ b/src/config/reader.cpp @@ -35,7 +35,7 @@ bool extractLine(const string& str, string* name, string* value); /// ***** Private Variables ***** -char* configDir = "../configs/"; +char* configDir = "configs/"; /// ***** Public Methods ***** -- 2.10.2 From 7ffb6c2da6f41929a6f8043d2127f28122864110 Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Thu, 28 Aug 2008 23:04:00 -0400 Subject: [PATCH 08/16] fix config reader bug --- src/config/reader.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/config/reader.cpp b/src/config/reader.cpp index 19f7d33..beb6e20 100644 --- a/src/config/reader.cpp +++ b/src/config/reader.cpp @@ -36,6 +36,7 @@ bool extractLine(const string& str, string* name, string* value); /// ***** Private Variables ***** char* configDir = "configs/"; +char* testFile = "test.cfg"; /// ***** Public Methods ***** @@ -44,7 +45,7 @@ void readConfigs(inputMap* map) char fileName[64]; strcpy(fileName, configDir); - strcat(fileName, "test.cfg"); + strcat(fileName, testFile); ifstream file(fileName); @@ -141,14 +142,17 @@ bool extractLine(const string& str, string* name, string* value) char_pos--; // decrement to stay on this char break; case 2: - if(c_str[char_pos] == '=') - state++; - if(c_str[char_pos] != ' ' - && c_str[char_pos] != '\t') + && c_str[char_pos] != '\t' + && c_str[char_pos] != '=') { return false; } + + if(c_str[char_pos] == '=') + { + state++; + } break; case 3: if(c_str[char_pos] != ' ' -- 2.10.2 From d6ce2baff0c3bfe8dce98d9b9325f84add6a2e72 Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Thu, 28 Aug 2008 23:58:13 -0400 Subject: [PATCH 09/16] change to SDLKey type --- src/input/inputManager.cpp | 8 ++++---- src/input/inputManager.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/input/inputManager.cpp b/src/input/inputManager.cpp index ebbd72e..3ecb477 100644 --- a/src/input/inputManager.cpp +++ b/src/input/inputManager.cpp @@ -93,20 +93,20 @@ bool input::mouseRight() return state & SDL_BUTTON(3); } -bool input::isPressed(Uint8 key) +bool input::isPressed(SDLKey key) { return keyState[key] == isP || keyState[key] == wasP; } -bool input::isReleased(Uint8 key) +bool input::isReleased(SDLKey key) { return keyState[key] == isR || keyState[key] == wasR; } -bool input::wasPressed(Uint8 key) +bool input::wasPressed(SDLKey key) { return keyState[key] == wasP; } -bool input::wasReleased(Uint8 key) +bool input::wasReleased(SDLKey key) { return keyState[key] == wasR; } diff --git a/src/input/inputManager.h b/src/input/inputManager.h index 13b6583..829dbc3 100644 --- a/src/input/inputManager.h +++ b/src/input/inputManager.h @@ -36,11 +36,11 @@ namespace input bool mouseLeft(); bool mouseRight(); - bool isPressed(Uint8); - bool isReleased(Uint8); + bool isPressed(SDLKey); + bool isReleased(SDLKey); - bool wasPressed(Uint8); - bool wasReleased(Uint8); + bool wasPressed(SDLKey); + bool wasReleased(SDLKey); } #endif // INPUT_H -- 2.10.2 From b552aa3b48a0b2a3e77523dfa0454265748bcf94 Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Fri, 29 Aug 2008 00:18:27 -0400 Subject: [PATCH 10/16] created key system, not yet used as there's a static bug --- src/Makefile | 1 + src/config/config.cpp | 8 ++++++++ src/config/keys.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/config/keys.h | 36 ++++++++++++++++++++++++++++++++++++ src/config/reader.cpp | 4 ++-- 5 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 src/config/keys.cpp create mode 100644 src/config/keys.h diff --git a/src/Makefile b/src/Makefile index 13c255e..a391724 100644 --- a/src/Makefile +++ b/src/Makefile @@ -47,6 +47,7 @@ SRCS += Effects/Screen.cpp SRCS += config/config.cpp SRCS += config/reader.cpp +SRCS += config/keys.cpp SRCS += input/inputManager.cpp diff --git a/src/config/config.cpp b/src/config/config.cpp index 9aa6f86..7d71e8a 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -17,6 +17,9 @@ #include "config.h" +#include +#include "keys.h" + #include "reader.h" #include "../input/inputManager.h" @@ -28,11 +31,16 @@ void cfg::init() { readConfigs(NULL); + // TODO read in config files + + key::init(); } void cfg::clean() { // TODO save to config files? + + key::clean(); } /// ***** Public Methods ***** diff --git a/src/config/keys.cpp b/src/config/keys.cpp new file mode 100644 index 0000000..6cd3cfd --- /dev/null +++ b/src/config/keys.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "keys.h" +#include "../debug.h" + +#include + +/// ***** Private Method Headers ***** +/// ***** Private Variables ***** + +/// ***** Initializers/Cleaners ***** +void key::init() +{ + pause = SDLK_PAUSE; + end = SDLK_ESCAPE; + + follow = SDLK_f; + + well = SDLK_SPACE; +} + +void key::clean() +{ +} diff --git a/src/config/keys.h b/src/config/keys.h new file mode 100644 index 0000000..9244a6f --- /dev/null +++ b/src/config/keys.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#ifndef KEYS_H +#define KEYS_H + +#include + +/// ***** Header Methods ***** +namespace key +{ + void init(); + void clean(); + + static SDLKey pause; + static SDLKey end; + static SDLKey follow; + static SDLKey well; +} + +#endif // KEYS_H diff --git a/src/config/reader.cpp b/src/config/reader.cpp index beb6e20..af2c43e 100644 --- a/src/config/reader.cpp +++ b/src/config/reader.cpp @@ -35,8 +35,8 @@ bool extractLine(const string& str, string* name, string* value); /// ***** Private Variables ***** -char* configDir = "configs/"; -char* testFile = "test.cfg"; +const char* configDir = "configs/"; +const char* testFile = "test.cfg"; /// ***** Public Methods ***** -- 2.10.2 From 1c880d7302f118237951eafcfe8fe661c7f41371 Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Fri, 29 Aug 2008 00:22:38 -0400 Subject: [PATCH 11/16] key control changed to new system --- src/config/config.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/config/config.cpp b/src/config/config.cpp index 7d71e8a..2df8b74 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -47,29 +47,29 @@ void cfg::clean() bool cfg::pause() { - return input::wasPressed(SDLK_p); + return input::wasPressed(key::pause); } bool cfg::unPause() { - return input::wasPressed(SDLK_p); + return input::wasPressed(key::pause); } bool cfg::endGame() { - return input::wasReleased(SDLK_ESCAPE); + return input::wasReleased(key::end); } bool cfg::mouseWellFollow() { - return input::isPressed(SDLK_f); + return input::isPressed(key::follow); } bool cfg::mouseWellOn() { - return input::wasPressed(SDLK_SPACE); + return input::wasPressed(key::well); } bool cfg::mouseWellOff() { - return input::wasReleased(SDLK_SPACE); + return input::wasReleased(key::well); } /// ***** Private Methods ***** -- 2.10.2 From c04d3365e5e66c2595257ebcd06191454ff6bff8 Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Fri, 29 Aug 2008 01:02:39 -0400 Subject: [PATCH 12/16] varible location differs in files ... static not working? --- src/config/config.cpp | 3 +++ src/config/keys.cpp | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/config/config.cpp b/src/config/config.cpp index 2df8b74..1e15c69 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -16,6 +16,7 @@ */ #include "config.h" +#include "../debug.h" #include #include "keys.h" @@ -35,6 +36,8 @@ void cfg::init() // TODO read in config files key::init(); + + cout << &key::end << endl; } void cfg::clean() { diff --git a/src/config/keys.cpp b/src/config/keys.cpp index 6cd3cfd..6a15f6e 100644 --- a/src/config/keys.cpp +++ b/src/config/keys.cpp @@ -26,14 +26,15 @@ /// ***** Initializers/Cleaners ***** void key::init() { - pause = SDLK_PAUSE; + pause = SDLK_p; end = SDLK_ESCAPE; follow = SDLK_f; well = SDLK_SPACE; -} + cout << &key::end << endl; +} void key::clean() { } -- 2.10.2 From 1878e7c1f8cef670e740a8f63f48afcb98386cdf Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Mon, 1 Sep 2008 23:42:15 -0400 Subject: [PATCH 13/16] keys setup to use extern --- src/config/config.cpp | 6 ------ src/config/keys.cpp | 23 +++++------------------ src/config/keys.h | 11 ++++------- 3 files changed, 9 insertions(+), 31 deletions(-) diff --git a/src/config/config.cpp b/src/config/config.cpp index 1e15c69..0980076 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -34,16 +34,10 @@ void cfg::init() readConfigs(NULL); // TODO read in config files - - key::init(); - - cout << &key::end << endl; } void cfg::clean() { // TODO save to config files? - - key::clean(); } /// ***** Public Methods ***** diff --git a/src/config/keys.cpp b/src/config/keys.cpp index 6a15f6e..6ac87bb 100644 --- a/src/config/keys.cpp +++ b/src/config/keys.cpp @@ -20,21 +20,8 @@ #include -/// ***** Private Method Headers ***** -/// ***** Private Variables ***** - -/// ***** Initializers/Cleaners ***** -void key::init() -{ - pause = SDLK_p; - end = SDLK_ESCAPE; - - follow = SDLK_f; - - well = SDLK_SPACE; - - cout << &key::end << endl; -} -void key::clean() -{ -} +/// ***** Definitions of the extern keys ***** +SDLKey key::pause = SDLK_p; +SDLKey key::end = SDLK_ESCAPE; +SDLKey key::follow = SDLK_f; +SDLKey key::well = SDLK_SPACE; diff --git a/src/config/keys.h b/src/config/keys.h index 9244a6f..42fd378 100644 --- a/src/config/keys.h +++ b/src/config/keys.h @@ -24,13 +24,10 @@ /// ***** Header Methods ***** namespace key { - void init(); - void clean(); - - static SDLKey pause; - static SDLKey end; - static SDLKey follow; - static SDLKey well; + extern SDLKey pause; + extern SDLKey end; + extern SDLKey follow; + extern SDLKey well; } #endif // KEYS_H -- 2.10.2 From 598fa0d50dedfcb47a8d88144ce9e37583aec23d Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Sun, 21 Sep 2008 20:34:31 -0400 Subject: [PATCH 14/16] added more start balls to slow things down on my desktop ... --- src/entityCreator.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/entityCreator.cpp b/src/entityCreator.cpp index fa16ae2..28d6979 100644 --- a/src/entityCreator.cpp +++ b/src/entityCreator.cpp @@ -73,6 +73,11 @@ void creator::init() ball = addBall(Vector2(150, 150), 20, cCyan, startBalls); ball->mass = startMass; + + for( int i = 0; i<100; i++) + { + addBall(Vector2(200+i*2, 200+i*2), 10, cCyan); + } } void creator::clean() { -- 2.10.2 From 338e728a60fc9135b534be4e8ad0bb43997a1ea4 Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Sun, 21 Sep 2008 23:02:11 -0400 Subject: [PATCH 15/16] fixed up the key mapping system a little ... still does comparisons wrong ... --- configs/{test.cfg => test1.cfg} | 2 + configs/test2.cfg | 2 + src/config/config.cpp | 3 +- src/config/keys.cpp | 18 ++++- src/config/keys.h | 28 +++++++ src/config/reader.cpp | 170 +++++++++++++++++++++------------------- src/config/reader.h | 4 +- 7 files changed, 138 insertions(+), 89 deletions(-) rename configs/{test.cfg => test1.cfg} (98%) create mode 100644 configs/test2.cfg diff --git a/configs/test.cfg b/configs/test1.cfg similarity index 98% rename from configs/test.cfg rename to configs/test1.cfg index c4d7b7f..524a754 100644 --- a/configs/test.cfg +++ b/configs/test1.cfg @@ -33,3 +33,5 @@ roger = flag0222 roger =flag2202 roger = flag2220 roger = flag2222 + +follow=k diff --git a/configs/test2.cfg b/configs/test2.cfg new file mode 100644 index 0000000..baf64f5 --- /dev/null +++ b/configs/test2.cfg @@ -0,0 +1,2 @@ +follow=k +well=LCtrl diff --git a/src/config/config.cpp b/src/config/config.cpp index 0980076..3b694ba 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -31,7 +31,8 @@ void cfg::init() { - readConfigs(NULL); + key::init(); + readConfigs(); // TODO read in config files } diff --git a/src/config/keys.cpp b/src/config/keys.cpp index 6ac87bb..e6eebf5 100644 --- a/src/config/keys.cpp +++ b/src/config/keys.cpp @@ -21,7 +21,17 @@ #include /// ***** Definitions of the extern keys ***** -SDLKey key::pause = SDLK_p; -SDLKey key::end = SDLK_ESCAPE; -SDLKey key::follow = SDLK_f; -SDLKey key::well = SDLK_SPACE; +SDLKey key::pause = SDLK_p; +SDLKey key::end = SDLK_ESCAPE; +SDLKey key::follow = SDLK_f; +SDLKey key::well = SDLK_SPACE; + +key::inputMap key::sdlMap; + +void key::init() +{ + key::sdlMap["pause"] = &key::pause; + key::sdlMap["end"] = &key::end; + key::sdlMap["follow"] = &key::follow; + key::sdlMap["well"] = &key::well; +} diff --git a/src/config/keys.h b/src/config/keys.h index 42fd378..49fe66f 100644 --- a/src/config/keys.h +++ b/src/config/keys.h @@ -21,6 +21,28 @@ #include +#include +#include + +#include "../debug.h" + +class comparestrings +{ + public: + bool operator() + ( + const std::string& a, + const std::string& b + ) + { + cout << a << endl; + cout << b << endl; + cout << endl; + + return a.compare(b) < 0; + } +}; + /// ***** Header Methods ***** namespace key { @@ -28,6 +50,12 @@ namespace key extern SDLKey end; extern SDLKey follow; extern SDLKey well; + + typedef std::map inputMap; + + extern inputMap sdlMap; + + void init(); } #endif // KEYS_H diff --git a/src/config/reader.cpp b/src/config/reader.cpp index af2c43e..c42e50d 100644 --- a/src/config/reader.cpp +++ b/src/config/reader.cpp @@ -22,28 +22,33 @@ #include #include +#include "keys.h" + using std::ifstream; using std::string; -typedef std::map kMap; +typedef std::map kMap; kMap keyMap; /// ***** Private Method Headers ***** -void processLine(const string& str, inputMap* map); +void processLine(const string& str); bool extractLine(const string& str, string* name, string* value); +void createKeyMap(); /// ***** Private Variables ***** const char* configDir = "configs/"; -const char* testFile = "test.cfg"; +const char* testFile = "test2.cfg"; /// ***** Public Methods ***** -void readConfigs(inputMap* map) +void readConfigs() { char fileName[64]; + createKeyMap(); + strcpy(fileName, configDir); strcat(fileName, testFile); @@ -63,7 +68,7 @@ void readConfigs(inputMap* map) if(file.eof()) break; - processLine(line, map); + processLine(line); } file.close(); @@ -71,7 +76,7 @@ void readConfigs(inputMap* map) /// ***** Private Methods ***** -void processLine(const string& str, inputMap* map) +void processLine(const string& str) { string name; string value; @@ -82,9 +87,15 @@ void processLine(const string& str, inputMap* map) if(extracted) { - //map->insert(name, value); + SDLKey key = keyMap[value]; + + if(0 != key) + { + *(key::sdlMap[name]) = key; + } cout << name << endl; cout << value << endl; + cout << key << endl; } } @@ -182,20 +193,12 @@ bool extractLine(const string& str, string* name, string* value) name->clear(); value->clear(); - name->replace(0, 0, c_str, name_start, name_end-name_start); - value->replace(0, 0, c_str, value_start, value_end-value_start); + name->replace (0, 0, c_str, name_start, name_end - name_start); + value->replace (0, 0, c_str, value_start, value_end - value_start); return true; } -bool extractKey(const string& str, Uint8* key) -{ -// if(str.length() != 1) -// return false; - - return false; -} - void createKeyMap() { // add all the letters @@ -208,6 +211,8 @@ void createKeyMap() for (int i = '0'; i <= '9'; i++) keyMap["" + (char)i] = (SDLKey)i; + keyMap["k"] = (SDLKey)'k'; + /* // add the function keys int F1 = (int)Key.F1; @@ -218,68 +223,71 @@ void createKeyMap() } */ - keyMap["LCtrl"] = SDLK_LCTRL; - keyMap["LeftControl"] = SDLK_LCTRL; - keyMap["LAlt"] = SDLK_LALT; - keyMap["LeftAlt"] = SDLK_LALT; - keyMap["LShift"] = SDLK_LSHIFT; - keyMap["LeftShift"] = SDLK_LSHIFT; - keyMap["LWin"] = SDLK_LSUPER; - keyMap["LeftWindows"] = SDLK_LSUPER; - keyMap["LeftMeta"] = SDLK_LMETA; - keyMap["LMeta"] = SDLK_LMETA; - - keyMap["RCtrl"] = SDLK_RCTRL; - keyMap["RightControl"] = SDLK_RCTRL; - keyMap["RAlt"] = SDLK_RALT; - keyMap["RightAlt"] = SDLK_RALT; - keyMap["RShift"] = SDLK_RSHIFT; - keyMap["RightShift"] = SDLK_RSHIFT; - keyMap["RWin"] = SDLK_RSUPER; - keyMap["RightWindows"] = SDLK_RSUPER; - keyMap["RightMeta"] = SDLK_RMETA; - keyMap["RMeta"] = SDLK_RMETA; - - keyMap["Esc"] = SDLK_ESCAPE; - keyMap["Escape"] = SDLK_ESCAPE; - - keyMap["Return"] = SDLK_RETURN; - keyMap["Enter"] = SDLK_RETURN; - - keyMap["Insert"] = SDLK_INSERT; - keyMap["Home"] = SDLK_HOME; - keyMap["Delete"] = SDLK_DELETE; - keyMap["End"] = SDLK_END; - keyMap["PageUp"] = SDLK_PAGEUP; - keyMap["PageDown"] = SDLK_PAGEDOWN; - - keyMap["Minus"] = SDLK_MINUS; - keyMap["Equal"] = SDLK_EQUALS; - keyMap["Equals"] = SDLK_EQUALS; - keyMap["LeftBracket"] = SDLK_LEFTBRACKET; - keyMap["LBracket"] = SDLK_LEFTBRACKET; - keyMap["RightBracket"] = SDLK_RIGHTBRACKET; - keyMap["RBracket"] = SDLK_RIGHTBRACKET; - keyMap["Backslash"] = SDLK_BACKSLASH; - keyMap["Slash"] = SDLK_SLASH; - keyMap["Semicolon"] = SDLK_SEMICOLON; - keyMap["Semi"] = SDLK_SEMICOLON; - keyMap["Quote"] = SDLK_QUOTE; - keyMap["Comma"] = SDLK_COMMA; - keyMap["Period"] = SDLK_PERIOD; - keyMap["Space"] = SDLK_SPACE; - keyMap["BSpace"] = SDLK_BACKSPACE; - keyMap["Backspace"] = SDLK_BACKSPACE; - keyMap["BackSpace"] = SDLK_BACKSPACE; - - keyMap["Tab"] = SDLK_TAB; - keyMap["BackQuote"] = SDLK_BACKQUOTE; - keyMap["BQuote"] = SDLK_BACKQUOTE; - keyMap["CapsLock"] = SDLK_CAPSLOCK; - keyMap["Caps"] = SDLK_CAPSLOCK; - - keyMap["Up"] = SDLK_UP; - keyMap["Down"] = SDLK_DOWN; - keyMap["Left"] = SDLK_LEFT; - keyMap["Right"] = SDLK_RIGHT; + keyMap["LCtrl"] = SDLK_LCTRL; + keyMap["LeftControl"] = SDLK_LCTRL; + keyMap["LAlt"] = SDLK_LALT; + keyMap["LeftAlt"] = SDLK_LALT; + keyMap["LShift"] = SDLK_LSHIFT; + keyMap["LeftShift"] = SDLK_LSHIFT; + keyMap["LWin"] = SDLK_LSUPER; + keyMap["LeftWindows"] = SDLK_LSUPER; + keyMap["LeftMeta"] = SDLK_LMETA; + keyMap["LMeta"] = SDLK_LMETA; + + keyMap["RCtrl"] = SDLK_RCTRL; + keyMap["RightControl"] = SDLK_RCTRL; + keyMap["RAlt"] = SDLK_RALT; + keyMap["RightAlt"] = SDLK_RALT; + keyMap["RShift"] = SDLK_RSHIFT; + keyMap["RightShift"] = SDLK_RSHIFT; + keyMap["RWin"] = SDLK_RSUPER; + keyMap["RightWindows"] = SDLK_RSUPER; + keyMap["RightMeta"] = SDLK_RMETA; + keyMap["RMeta"] = SDLK_RMETA; + + keyMap["Esc"] = SDLK_ESCAPE; + keyMap["Escape"] = SDLK_ESCAPE; + + keyMap["Return"] = SDLK_RETURN; + keyMap["Enter"] = SDLK_RETURN; + + keyMap["Insert"] = SDLK_INSERT; + keyMap["Home"] = SDLK_HOME; + keyMap["Delete"] = SDLK_DELETE; + keyMap["End"] = SDLK_END; + keyMap["PageUp"] = SDLK_PAGEUP; + keyMap["PageDown"] = SDLK_PAGEDOWN; + + keyMap["Minus"] = SDLK_MINUS; + keyMap["Equal"] = SDLK_EQUALS; + keyMap["Equals"] = SDLK_EQUALS; + keyMap["LeftBracket"] = SDLK_LEFTBRACKET; + keyMap["LBracket"] = SDLK_LEFTBRACKET; + keyMap["RightBracket"] = SDLK_RIGHTBRACKET; + keyMap["RBracket"] = SDLK_RIGHTBRACKET; + keyMap["Backslash"] = SDLK_BACKSLASH; + keyMap["Slash"] = SDLK_SLASH; + keyMap["Semicolon"] = SDLK_SEMICOLON; + keyMap["Semi"] = SDLK_SEMICOLON; + keyMap["Quote"] = SDLK_QUOTE; + keyMap["Comma"] = SDLK_COMMA; + keyMap["Period"] = SDLK_PERIOD; + keyMap["Space"] = SDLK_SPACE; + keyMap["BSpace"] = SDLK_BACKSPACE; + keyMap["Backspace"] = SDLK_BACKSPACE; + keyMap["BackSpace"] = SDLK_BACKSPACE; + + keyMap["Tab"] = SDLK_TAB; + keyMap["BackQuote"] = SDLK_BACKQUOTE; + keyMap["BQuote"] = SDLK_BACKQUOTE; + keyMap["CapsLock"] = SDLK_CAPSLOCK; + keyMap["Caps"] = SDLK_CAPSLOCK; + + keyMap["Up"] = SDLK_UP; + keyMap["Down"] = SDLK_DOWN; + keyMap["Left"] = SDLK_LEFT; + keyMap["Right"] = SDLK_RIGHT; + + cout << "done" << endl; + cout << keyMap["k"] << endl; } diff --git a/src/config/reader.h b/src/config/reader.h index eb13cbc..a978da2 100644 --- a/src/config/reader.h +++ b/src/config/reader.h @@ -25,10 +25,8 @@ using std::string; -typedef std::map inputMap; - /// ***** Header Methods ***** -void readConfigs(inputMap*); +void readConfigs(); #endif // READER_H -- 2.10.2 From e268f6ef72bca3f090ad46451fbe66ee5b31c066 Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Mon, 22 Sep 2008 21:28:06 -0400 Subject: [PATCH 16/16] fixed string problems --- src/config/keys.h | 19 +------------------ src/config/reader.cpp | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/config/keys.h b/src/config/keys.h index 49fe66f..31dfcdd 100644 --- a/src/config/keys.h +++ b/src/config/keys.h @@ -26,23 +26,6 @@ #include "../debug.h" -class comparestrings -{ - public: - bool operator() - ( - const std::string& a, - const std::string& b - ) - { - cout << a << endl; - cout << b << endl; - cout << endl; - - return a.compare(b) < 0; - } -}; - /// ***** Header Methods ***** namespace key { @@ -51,7 +34,7 @@ namespace key extern SDLKey follow; extern SDLKey well; - typedef std::map inputMap; + typedef std::map inputMap; extern inputMap sdlMap; diff --git a/src/config/reader.cpp b/src/config/reader.cpp index c42e50d..4e27d93 100644 --- a/src/config/reader.cpp +++ b/src/config/reader.cpp @@ -27,7 +27,7 @@ using std::ifstream; using std::string; -typedef std::map kMap; +typedef std::map kMap; kMap keyMap; /// ***** Private Method Headers ***** @@ -201,17 +201,26 @@ bool extractLine(const string& str, string* name, string* value) void createKeyMap() { + char buf[2] = {0,0}; + // add all the letters for (int i = 'A'; i <= 'Z'; i++) // uppercase - keyMap["" + (char)i] = (SDLKey)i; + { + buf[0] = (char)i; + keyMap[buf] = (SDLKey)i; + } for (int i = 'a'; i <= 'z'; i++) // lowercase - keyMap["" + (char)i] = (SDLKey)i; + { + buf[0] = (char)i; + keyMap[buf] = (SDLKey)i; + } // add all the numbers for (int i = '0'; i <= '9'; i++) - keyMap["" + (char)i] = (SDLKey)i; - - keyMap["k"] = (SDLKey)'k'; + { + buf[0] = (char)i; + keyMap[buf] = (SDLKey)i; + } /* // add the function keys @@ -287,7 +296,4 @@ void createKeyMap() keyMap["Down"] = SDLK_DOWN; keyMap["Left"] = SDLK_LEFT; keyMap["Right"] = SDLK_RIGHT; - - cout << "done" << endl; - cout << keyMap["k"] << endl; } -- 2.10.2