瀏覽代碼

* added missing files
* fixed displaying objects
* fixed memory leak

Michał W. Urbańczyk 18 年之前
父節點
當前提交
32baadfbfa
共有 3 個文件被更改,包括 113 次插入5 次删除
  1. 72 0
      CLua.cpp
  2. 36 0
      CLua.h
  3. 5 5
      hch/CObjectHandler.cpp

+ 72 - 0
CLua.cpp

@@ -0,0 +1,72 @@
+#include "stdafx.h"
+#include "CLua.h"
+#include "CLuaHandler.h"
+#include "lualib.h"
+#include "lauxlib.h"
+
+CObjectScript::CObjectScript()
+{
+	//std::cout << "Tworze obiekt objectscript "<<this<<std::endl;
+}
+
+CObjectScript::~CObjectScript()
+{
+	//std::cout << "Usuwam obiekt objectscript "<<this<<std::endl;
+}
+
+CScript::CScript()
+{
+	//std::cout << "Tworze obiekt CScript "<<this<<std::endl;
+}
+CScript::~CScript()
+{
+	//std::cout << "Usuwam obiekt CScript "<<this<<std::endl;
+}
+
+#define LST (is)
+CLua::CLua(std::string initpath)
+{
+	opened=false;
+	LST = lua_open();
+	opened = true;
+	LUA_OPEN_LIB(LST, luaopen_base);
+	LUA_OPEN_LIB(LST, luaopen_io);
+	if ((luaL_loadfile (LST, "test.lua")) == 0)
+	{
+		//lua_pcall (LST, 0, LUA_MULTRET, 0);
+	}
+	else
+	{
+		std::string temp = "Cannot open script";
+		temp += initpath;
+		throw std::exception(temp.c_str());
+	}
+}
+CLua::CLua()
+{
+	//std::cout << "Tworze obiekt clua "<<this<<std::endl;
+	opened=false;
+}
+void CLua::registerCLuaCallback()
+{
+}
+
+CLua::~CLua()
+{
+	//std::cout << "Usuwam obiekt clua "<<this<<std::endl;
+	if (opened)
+	{
+		std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<std::endl;
+		lua_close(LST);
+	}
+}
+#undef LST
+
+CLuaObjectScript::CLuaObjectScript()
+{
+	//std::cout << "Tworze obiekt CLuaObjectScript "<<this<<std::endl;
+}
+CLuaObjectScript::~CLuaObjectScript()
+{
+	//std::cout << "Usuwam obiekt CLuaObjectScript "<<this<<std::endl;
+}

+ 36 - 0
CLua.h

@@ -0,0 +1,36 @@
+#include "global.h"
+#include "lstate.h"
+class CLua;
+class CObjectScript
+{
+public:
+	int owner;
+	int getOwner(){return owner;} //255 - neutral /  254 - not flaggable
+	CObjectScript();
+	virtual ~CObjectScript();
+};
+class CScript
+{
+public:
+	CScript();
+	virtual ~CScript();
+};
+
+class CLua :public CScript
+{
+	lua_State * is; /// tez niebezpieczne!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ale chwilowo okielznane)
+	bool opened;
+public:
+	CLua(std::string initpath);
+	void registerCLuaCallback();
+	CLua();
+	virtual ~CLua();
+};
+
+class CLuaObjectScript : public CLua, public CObjectScript
+{
+public:
+	CLuaObjectScript();
+	virtual ~CLuaObjectScript();
+
+};

+ 5 - 5
hch/CObjectHandler.cpp

@@ -99,13 +99,13 @@ bool CGObjectInstance::operator<(const CGObjectInstance & cmp) const  //screen p
 		return true;
 	if(this->pos.y>cmp.pos.y)
 		return false;
-	if(defInfo->isOnDefList && !(defInfo->isOnDefList))
+	if(defInfo->isOnDefList && !(cmp.defInfo->isOnDefList))
 		return true;
-	if(defInfo->isOnDefList && !(defInfo->isOnDefList))
+	if(cmp.defInfo->isOnDefList && !(defInfo->isOnDefList))
 		return false;
-	if(!defInfo->isVisitable() && defInfo->isVisitable())
+	if(!defInfo->isVisitable() && cmp.defInfo->isVisitable())
 		return true;
-	if(!defInfo->isVisitable() && defInfo->isVisitable())
+	if(!cmp.defInfo->isVisitable() && defInfo->isVisitable())
 		return false;
 	if(this->pos.x<cmp.pos.x)
 		return true;
@@ -258,7 +258,7 @@ CGObjectInstance& CGObjectInstance::operator=(const CGObjectInstance & right)
 	defInfo = right.defInfo;
 	info = right.info;
 	defObjInfoNumber = right.defObjInfoNumber;
-	state = new CLuaObjectScript();
+	//state = new CLuaObjectScript();
 	*state = *right.state;
 	return *this;
 }