diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..092d5ca --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +a.out +db + diff --git a/database/db.cpp b/database/db.cpp index 4e78619..63664a4 100644 --- a/database/db.cpp +++ b/database/db.cpp @@ -70,6 +70,11 @@ void PosDb::acceptLogEntry(const LogEntry & l) { break; } + case ET_PRICE: { + upc_to_price[l.PriceChange.upc] = l.PriceChange.price; + break; + } + case ET_REVERT: { sto_it q = serial_to_object.find(l.Revert.revert_serial); if((q == serial_to_object.end()) || (q->second.type != ET_TRANS)) { @@ -172,7 +177,7 @@ uint64_t PosDb::deassociateHash(const SHA1Hash & hash) { } else { LogEntry l; memset(&l, 0, sizeof(LogEntry)); - l.ts = (uint64_t)time(NULL); + l.ts = (uint64_t)time(NULL); l.type = ET_HASH; l.HashChange.uid = acct; l.HashChange.add = false; @@ -184,6 +189,26 @@ uint64_t PosDb::deassociateHash(const SHA1Hash & hash) { } } +int32_t PosDb::getUPCPrice(UPC upc) { + uts_it it = upc_to_price.find(upc); + if (it == upc_to_price.end()) { + return 0; + } + return it->second; +} + +uint64_t PosDb::setUPCPrice(UPC upc, int32_t price) { + LogEntry l; + memset(&l, 0, sizeof(LogEntry)); + l.ts = (uint64_t)time(NULL); + l.type = ET_PRICE; + l.PriceChange.upc = upc; + l.PriceChange.price = price; + l.serial = log.nextSerial(); + acceptLogEntry(l); + return log.writeEntry(l); +} + uint64_t PosDb::doTransaction(const SHA1Hash & hash, int32_t delta) { // verify hash associated with something uint32_t acct = getAccountFromHash(hash); diff --git a/database/db.h b/database/db.h index df52426..f836276 100644 --- a/database/db.h +++ b/database/db.h @@ -23,6 +23,9 @@ public: uint64_t associateHash(const SHA1Hash & hash, std::string account); uint64_t deassociateHash(const SHA1Hash & hash); + int32_t getUPCPrice(UPC upc); + uint64_t setUPCPrice(UPC upc, int32_t price); + uint64_t doTransaction(const SHA1Hash & hash, int32_t delta); uint64_t doTransaction(const uint32_t account, int32_t delta); uint64_t doTransaction(std::string account, int32_t delta); @@ -38,6 +41,7 @@ private: std::map account_to_balance; std::map upc_to_stock; + std::map upc_to_price; std::map serial_to_object; diff --git a/database/log.h b/database/log.h index f2d9320..66a907d 100644 --- a/database/log.h +++ b/database/log.h @@ -5,7 +5,7 @@ #include #include -enum E_OBJ_TYPE { ET_TRANS, ET_HASH, ET_SALE, ET_REVERT }; +enum E_OBJ_TYPE { ET_TRANS, ET_HASH, ET_SALE, ET_PRICE, ET_REVERT }; struct __attribute__ ((packed)) UPC { uint64_t h, l; @@ -43,6 +43,11 @@ struct __attribute__ ((aligned (64), packed)) LogEntry int32_t delta; } StockChange; + struct __attribute__ ((packed)) { + UPC upc; + int32_t price; + } PriceChange; + struct __attribute__ ((packed)) { uint64_t revert_serial; } Revert; diff --git a/database/nameserver.cpp b/database/nameserver.cpp index e000a69..ff9e89e 100644 --- a/database/nameserver.cpp +++ b/database/nameserver.cpp @@ -19,7 +19,6 @@ uint32_t NameServer::get_id (std::string name) { std::cerr << "Doing LDAP lookup for \"" << name << "\".\n"; struct passwd* pwd = getpwnam(name.c_str()); if (!pwd) { - std::cerr << "Username " << name << " lookup fail!\n"; // TODO: oh fuck??? return 0; } diff --git a/database/tests.cpp b/database/tests.cpp index 2255faf..13d4f5e 100644 --- a/database/tests.cpp +++ b/database/tests.cpp @@ -25,6 +25,8 @@ int main() { UPC foo; foo.l = 12345; foo.h = 67890; + cout << db.setUPCPrice(foo, db.getUPCPrice(foo) + 1) << "\n"; + cout << "price: " << db.getUPCPrice(foo) << "\n"; cout << db.doStockChange(foo, 100) << "\n"; cout << db.getStock(foo) << "\n"; foo.l = 123; diff --git a/main.cpp b/main.cpp index 1e713e0..03ab2b9 100644 --- a/main.cpp +++ b/main.cpp @@ -75,7 +75,7 @@ void render () { ); static float x = 0; glTranslatef (-8,0,-20); - glRotatef (x+=1.0, 0,1,0); + glRotatef (x+=0.01, 0,1,0); glRotatef (30.0, 1.0,0,0); GLint shader_tex_loc = glGetUniformLocation(shaders[0].prog_id, "texture"); @@ -253,7 +253,7 @@ void GL_init (float w, float h) { } int main () { - float scale = 3; + float scale = 1; float w = 480*scale; float h = 272*scale; if (!glfwInit () || !glfwOpenWindow (w, h, 8,8,8,0,32,0,GLFW_WINDOW)) {