git » fp-git.git » commit 2daad6f

added hash table

author ecalot
2006-05-27 12:52:20 UTC
committer ecalot
2006-05-27 12:52:20 UTC
parent b0ccb22718c69dfc39123fa6aad36436c5dd9cf0

added hash table

PV4/include/level.h +12 -1
PV4/src/endiansafestream.cpp +17 -13
PV4/src/level.cpp +20 -15
PV4/src/main.cpp +1 -1
PV4/src/pop1levelformat.cpp +2 -2

diff --git a/PV4/include/level.h b/PV4/include/level.h
index 044574b..a9cfd33 100644
--- a/PV4/include/level.h
+++ b/PV4/include/level.h
@@ -1,11 +1,13 @@
 #ifndef _LEVEL_H_
 #define _LEVEL_H_
 
-#include <string>
 #include "levelformat.h"
 #include "guard.h"
 #include "tile.h"
 
+#include <map>
+#include <string>
+
 class Level {
 public:
 	Level(const char* file); //open
@@ -16,6 +18,7 @@ public:
 
 	~Level();
 
+	map<const char*,const char*>* getInfo();
 	/*
 	plvInfo getInfo();
 	setInfo(plvInfo i);
@@ -54,8 +57,11 @@ public:
 	bool redo()
 	*/
 
+	map<const char*,const char*> info;
+
 private:
 	string* fileName;
+
 #define MATRIX_HEIGHT (31+1+31)
 #define MATRIX_WIDTH (31+1+31)
 
@@ -89,6 +95,11 @@ private:
 
 	int addScreen(int x, int y);
 
+	//Configuration
+	bool checkIntegrity;
+	bool genericLinks;
+	
 };
 
 #endif
+
diff --git a/PV4/src/endiansafestream.cpp b/PV4/src/endiansafestream.cpp
index f3f7e4e..0c5106d 100644
--- a/PV4/src/endiansafestream.cpp
+++ b/PV4/src/endiansafestream.cpp
@@ -6,33 +6,37 @@
 using namespace std;
 
 iesstream::iesstream(const char* file) {
-   this->open(file,ios::in|ios::binary);
-   if (!this->is_open()) throw -2;
+	this->open(file,ios::in|ios::binary);
+	if (!this->is_open()) throw -2;
 }
 
 void iesstream::read(unsigned char& c) {
-         this->read((char*)&c,1);
+	this->read((char*)&c,1);
 }
 
 void iesstream::read(char &c){
 	this->read(&c,1);
-         }
+}
 
 void iesstream::read(long &l){
-         this->read((char*)&l,4);
-         }
+	l=0;
+	this->read((char*)&l,4);
+}
 
 void iesstream::read(unsigned long &l){
+	l=0;
 	this->read((char*)&l,4);
-	}
+}
 
- void iesstream::read(short &s){
-	 this->read((char*)&s,2);
-	 }
+void iesstream::read(short &s){
+	s=0;
+	this->read((char*)&s,2);
+}
 
-  void iesstream::read(unsigned short &s){
-		this->read((char*)&s,2);
-		}
+void iesstream::read(unsigned short &s){
+	s=0;
+	this->read((char*)&s,2);
+}
 
 void iesstream::read(unsigned char* c,int size){
 	this->read((char*)c,size);
diff --git a/PV4/src/level.cpp b/PV4/src/level.cpp
index 947ed4c..0c8a9b1 100644
--- a/PV4/src/level.cpp
+++ b/PV4/src/level.cpp
@@ -30,7 +30,7 @@ typedef char* fieldPointer;
 Level::Level(const char* file) { //open
 	//open the file
   iesstream stream(file);
-cout<<"Opening level "<< file <<endl;
+//cout<<"Opening level "<< file <<endl;
 
 	//check the magic
 	char magic[7];
@@ -63,7 +63,7 @@ cout<<"Opening level "<< file <<endl;
 
 	switch (popVersion) {
 		case 1:
-cout<<"is pop1"<<endl;
+//cout<<"is pop1"<<endl;
 			this->level=new Pop1LevelFormat(stream,b1);
 			break;
 		case 2:
@@ -75,11 +75,11 @@ cout<<"is pop1"<<endl;
 	//user data size
 	unsigned long b2;
 	stream.read(b2);
+//cout<<"b2 "<<b2<<endl;
 
-	//alloc user data (TODO: use integrity checks here)
+	//alloc user data (TODO: use integrity checks here before doing the allocation)
 	char* ud=new char[b2];
 	stream.read(ud,b2);
-cout<<"nf "<<nf<<endl;
 
 	//process user data
 	fieldPointer* fields=new fieldPointer[nf*2];
@@ -92,19 +92,24 @@ cout<<"nf "<<nf<<endl;
 
 	for (unsigned int i=0;i<nf;i++) {
 		cout<<"f['"<<fields[i*2]<<"']='"<<fields[i*2+1]<<"'"<<endl;
+		info[fields[i*2]]=fields[i*2+1];
 	}
 
-	if (currentField!=nf*2 || ud[b2-1]!=0) throw -2;
-cout<<"cf "<<currentField<<" nf "<<nf<<" b2 "<<b2<<endl;
+	if (currentField!=nf*2 || ud[b2-1]!=0) throw -4;
+//cout<<"cf "<<currentField<<" nf "<<nf<<" b2 "<<b2<<endl;
 
 	//TODO: generate a hash table with this values
 
 	//remember the file name
 	this->fileName=new string(file);
-cout<<"ok"<<endl;
+//cout<<"ok"<<endl;
 
 	//Finally arrange the rooms
 	this->arrangeRooms();
+
+	//Free memory
+	//delete[] fields;
+	delete[] ud;
 }
 
 Level::Level(int popVersion,int LevelNumber){} // new
@@ -114,10 +119,9 @@ void Level::save(const char* file){}
 
 Level::~Level(){}
 
-/*
-plvInfo Level::getInfo()
-Level::setInfo(plvInfo i)
-*/
+map<const char*,const char*>* Level::getInfo() { //TODO: decide if let map as public and forget about this
+	return &(this->info);
+}
 
 void Level::linkRecurse(int x, int y, int room) {
  if (matrix(x,y)==-1) {
@@ -218,10 +222,10 @@ int Level::getWidth(){
  return (this->ce-this->cs-1)*10+2;
 }
 
-bool Level::addGuard(int floor,int col,Guard g){}
-bool Level::delGuard(int floor,int col){}
-bool Level::moveGuard(int floor,int col,int nfloor,int ncol){}
-bool Level::getGuard(int floor,int col,Guard &g){}
+bool Level::addGuard(int floor,int col,Guard g){return false;}
+bool Level::delGuard(int floor,int col){return false;}
+bool Level::moveGuard(int floor,int col,int nfloor,int ncol){return false;}
+bool Level::getGuard(int floor,int col,Guard &g){return false;}
 /*vector <floor,col> getGuards()*/
 
 
@@ -285,6 +289,7 @@ int Level::addScreen(int x, int y) {
 
 	//recalculate
 	this->arrangeRooms();
+	return 0; //TODO: return true if the level must be redrawn!
 }
 
 //TODO: delScreen
diff --git a/PV4/src/main.cpp b/PV4/src/main.cpp
index 5275878..05e3378 100644
--- a/PV4/src/main.cpp
+++ b/PV4/src/main.cpp
@@ -10,7 +10,7 @@ int main(int argc, char *argv[])
 {
 
 try {
-	Level l("lev\\level002.plv");
+	Level l("lev/level2.plv");
 
 	int w,h;
 
diff --git a/PV4/src/pop1levelformat.cpp b/PV4/src/pop1levelformat.cpp
index 86631cb..0932aa4 100644
--- a/PV4/src/pop1levelformat.cpp
+++ b/PV4/src/pop1levelformat.cpp
@@ -206,8 +206,8 @@ void Pop1LevelFormat::setStartPosition(int screen, int location,Direction direct
 	this->start_position[2]=(unsigned char)direction;
 }
 
-bool Pop1LevelFormat::getDebugPosition(int &screen, int &location,Direction &direction) {}
-bool Pop1LevelFormat::setDebugPosition(int screen, int location,Direction direction) {}
+bool Pop1LevelFormat::getDebugPosition(int &screen, int &location,Direction &direction) {return false;}
+bool Pop1LevelFormat::setDebugPosition(int screen, int location,Direction direction) {return false;}
 void Pop1LevelFormat::clearDebugPosition() {}
 
 /* Doors */