Skip to content

Commit

Permalink
fix-error
Browse files Browse the repository at this point in the history
  • Loading branch information
cuiwenyao committed Jul 16, 2021
1 parent 2f5cab1 commit d426a57
Show file tree
Hide file tree
Showing 70 changed files with 158 additions and 1,312 deletions.
26 changes: 21 additions & 5 deletions code/Driver/GlobalDriver/GlobalIODriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ void XYY_GlobalIODriver::init(XYY_Window * win)
/*注册回调函数*/
//回调函数用在全局控制上面 日后写全局驱动的话,将全局的回调写上去。
//对于普通物体的IO控制,就不太需要回调函数了。
glfwSetFramebufferSizeCallback(win->getwindow(), window_framebuffer_size_callback );
//glfwSetFramebufferSizeCallback(win->getwindow(), window_framebuffer_size_callback );
//glfwSetCursorPosCallback(win->getwindow(), window_mouse_callback);
//glfwSetScrollCallback(win->getwindow(), window_scroll_callback);
//glfwSetMouseButtonCallback(win->getwindow(),window_mouse_button_callback);
glfwSetKeyCallback(win->getwindow(), window_key_callback);
//std::cout << "成功注册回调函数" << std::endl;


/* 初始化鼠标为第一次操作 */
firstMouse = true;

// game init
if (_initFunc) (*initFunc)();

}

void XYY_GlobalIODriver::run(XYY_SceneContent * sc,XYY_Window * win, XYY_GlobalSyncDriver * sync)
Expand Down Expand Up @@ -67,9 +70,22 @@ void XYY_GlobalIODriver::run(XYY_SceneContent * sc,XYY_Window * win, XYY_GlobalS
// 修改当前相机,后面可以改为调度全局IO控制
// std::cout << xoffset << ' ' << yoffset << std::endl;
sc->Cameras[0]->ProcessMouseMovement(xoffset, yoffset);

// game running
if (_runFunc) (*runFunc)(sc,win,sync);



}

void XYY_GlobalIODriver::setInitFunc(void (*initFunc)())
{
this->_initFunc = true;
this->initFunc = initFunc;
}

void XYY_GlobalIODriver::setRunFunc(void (*runFunc)(XYY_SceneContent* sc, XYY_Window* win, XYY_GlobalSyncDriver* sync))
{
this->_runFunc = true;
this->runFunc = runFunc;
}


Expand All @@ -82,7 +98,7 @@ void XYY_GlobalIODriver::window_seticon_callback(const std::string& iconpath)
}
void XYY_GlobalIODriver::window_framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
// glViewport(0, 0, width, height);
}

void XYY_GlobalIODriver::window_mouse_callback(GLFWwindow* window, double xpos, double ypos)
Expand Down
13 changes: 12 additions & 1 deletion code/Driver/GlobalDriver/GlobalIODriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "./GlobalDriver.h"
#include "./GlobalSyncDriver.h"

class __declspec(dllexport) XYY_GlobalIODriver : public XYY_GlobalDriver
class __declspec(dllexport) XYY_GlobalIODriver : public XYY_GlobalDriver
{
public:
float mouselastX;//鼠标横坐标
Expand All @@ -25,4 +25,15 @@ class __declspec(dllexport) XYY_GlobalIODriver : public XYY_GlobalDriver
static void window_scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
static void window_mouse_button_callback(GLFWwindow* window, int button, int action, int mods);
static void window_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);

// 设置初始化 与 运行回调函数
void setInitFunc(void (*initFunc)());
void setRunFunc(void (*runFunc)(XYY_SceneContent* sc, XYY_Window* win, XYY_GlobalSyncDriver* sync ));

private:
void (*initFunc)(); // 外部 初始化函数
bool _initFunc = false;

void (*runFunc)(XYY_SceneContent* sc, XYY_Window* win, XYY_GlobalSyncDriver* sync); // 外部 运行函数
bool _runFunc = false;
};
16 changes: 14 additions & 2 deletions code/Driver/GlobalDriver/GlobalLogicDriver.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
#include "./GlobalLogicDriver.h"

void XYY_GlobalLogicDriver::init()
void XYY_GlobalLogicDriver::init(XYY_SceneContent* sc)
{
// game init

if(_initFunc) (*initFunc)(sc);
}

void XYY_GlobalLogicDriver::run(XYY_SceneContent * sc)
{
// game running
if(_runFunc) (*runFunc)(sc);
}

void XYY_GlobalLogicDriver::setInitFunc(void (*initFunc)(XYY_SceneContent* sc))
{
this->_initFunc = true;
this->initFunc = initFunc;
}

void XYY_GlobalLogicDriver::setRunFunc(void (*runFunc)(XYY_SceneContent* sc))
{
this->_runFunc = true;
this->runFunc = runFunc;
}
13 changes: 12 additions & 1 deletion code/Driver/GlobalDriver/GlobalLogicDriver.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once


#include "./GlobalDriver.h"

/*
Expand All @@ -9,7 +10,17 @@
class __declspec(dllexport) XYY_GlobalLogicDriver : XYY_GlobalDriver
{
public:
void init();

void init(XYY_SceneContent* sc);
void run(XYY_SceneContent * sc);
void setInitFunc( void (*initFunc)(XYY_SceneContent* sc) );
void setRunFunc( void (*runFunc)(XYY_SceneContent* sc) );

private:
void (*initFunc)(XYY_SceneContent* sc); // 外部 初始化函数
bool _initFunc = false;

void (*runFunc)(XYY_SceneContent* sc); // 外部 运行函数
bool _runFunc = false;

};
10 changes: 2 additions & 8 deletions code/Element/Element.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
#pragma once

#include <vector>
#include <map>
#include "../Driver/LocalDriver/LocalDriver.h"
#include "../Driver/LocalDriver/LocalRendDriver.h"
#include "../Driver/LocalDriver/LocalLightDriver.h"



class __declspec(dllexport) XYY_Element
{
public:
unsigned int type; // 元素的种类编号 定义为: 0:灯光 1:普通物体 2:其他(天空盒等)
// std::vector<XYY_LocalDriver *> ld; // 该元素所拥有的局部驱动 定义为: 0:渲染 1:物理 2:动画


std::string id = "0"; // 元素标识器

// unsigned int id; // 元素的id 唯一标识一个元素




};

2 changes: 1 addition & 1 deletion code/Scene/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void XYY_Scene::run()
gd_sync->init();
gd_io->init(win);
gd_lightrend->init();
gd_logic->init();
gd_logic->init(sc);
gd_debugout->init();

while ( !glfwWindowShouldClose( win->getwindow() ) )
Expand Down
98 changes: 83 additions & 15 deletions code/Scene/SceneContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,31 @@ XYY_SceneContent::XYY_SceneContent()
skybox = NULL;
return;
}

// 元素ID管理
void XYY_SceneContent::setEleID(XYY_Element* ele, std::string id)
{
idmap[id] = ele;
return;
}

XYY_Element* XYY_SceneContent::getEle(std::string id)
{
if (idmap.find(id) == idmap.end())
{
std::cout << '*' << std::endl;
return NULL;
}
else return idmap[id];
}


/*
XML场景解析模块待做:
2、更加完善的属性编辑
3、base 整体迁移 ( 多XMl文件引用 )
*/
bool XYY_SceneContent::loadXML(const char * path)
bool XYY_SceneContent::XYY_SceneContent::loadXML(const char * path,bool setloc,glm::vec3 base )
{
// XML文档
TiXmlDocument doc;
Expand All @@ -29,7 +48,6 @@ bool XYY_SceneContent::loadXML(const char * path)
}

// 建立默认 shader
//c++ 的目录以程序运行的目录问基准,即以项目配置文件所在位置为基准,所以main入口文件和start入口文件要保持同级目录。
XYY_ShaderResource * defaultobjectshader = new XYY_ShaderResource("include/GLSL/object.vert", "include/GLSL/object.frag");
XYY_ShaderResource * defaultskyboxshader = new XYY_ShaderResource("include/GLSL/skybox.vert", "include/GLSL/skybox.frag");

Expand All @@ -38,6 +56,9 @@ bool XYY_SceneContent::loadXML(const char * path)
std::map<std::string, XYY_TextureResource *> TextureMap; // 纹理复用
std::map<std::string, XYY_ShaderResource *> ShaderMap; // Shader复用,暂未实现

// 多XML引入基准坐标
glm::vec3 bloc = setloc ? base : glm::vec3(0, 0, 0);

// 遍历子节点
for (TiXmlElement *elem = root->FirstChildElement(); elem != NULL; elem = elem->NextSiblingElement())
{
Expand Down Expand Up @@ -94,10 +115,8 @@ bool XYY_SceneContent::loadXML(const char * path)
if (sonele->Attribute("positionx")) px = true, posx = sonele->Attribute("positionx");// std::cout << " " << "positionx:" << sonele->Attribute("positionx") << std::endl;
if (sonele->Attribute("positiony")) py = true, posy = sonele->Attribute("positiony");// std::cout << " " << "positiony:" << sonele->Attribute("positiony") << std::endl;
if (sonele->Attribute("positionz")) pz = true, posz = sonele->Attribute("positionz");// std::cout << " " << "positionz:" << sonele->Attribute("positionz") << std::endl;
if (px || py || pz)
{
obj->ld_rend->setposition( glm::vec3( atof( posx.c_str() ) , atof(posy.c_str()) , atof(posz.c_str()) ) );
}

obj->ld_rend->setposition(bloc + glm::vec3( atof( posx.c_str() ) , atof(posy.c_str()) , atof(posz.c_str()) ) );

// scalex scaley scalez
std::string scalex = "1"; bool _scalex = false;
Expand All @@ -111,6 +130,12 @@ bool XYY_SceneContent::loadXML(const char * path)
obj->ld_rend->Stretch(glm::vec3(atof(scalex.c_str()), atof(scaley.c_str()), atof(scalez.c_str())));
}

// id
std::string id = "0"; bool _id = false;
if (sonele->Attribute("id")) _id = true, id = sonele->Attribute("id");
obj->id = id;
setEleID( obj , id );

Objects.push_back(obj);
}
else if (sonelenName == "cube")
Expand Down Expand Up @@ -142,10 +167,10 @@ bool XYY_SceneContent::loadXML(const char * path)
if (sonele->Attribute("positionx")) px = true, posx = sonele->Attribute("positionx");// std::cout << " " << "positionx:" << sonele->Attribute("positionx") << std::endl;
if (sonele->Attribute("positiony")) py = true, posy = sonele->Attribute("positiony");// std::cout << " " << "positiony:" << sonele->Attribute("positiony") << std::endl;
if (sonele->Attribute("positionz")) pz = true, posz = sonele->Attribute("positionz");// std::cout << " " << "positionz:" << sonele->Attribute("positionz") << std::endl;
if (px || py || pz)
{
cube->ld_rend->setposition(glm::vec3(atof(posx.c_str()), atof(posy.c_str()), atof(posz.c_str())));
}

// std::cout << bloc.x << ',' << bloc.y << ',' << bloc.z << std::endl;
cube->ld_rend->setposition(bloc + glm::vec3(atof(posx.c_str()), atof(posy.c_str()), atof(posz.c_str())));


// scalex scaley scalez
std::string scalex = "1"; bool _scalex = false;
Expand Down Expand Up @@ -187,6 +212,12 @@ bool XYY_SceneContent::loadXML(const char * path)
}
}

// id
std::string id = "0"; bool _id = false;
if (sonele->Attribute("id")) _id = true, id = sonele->Attribute("id");
cube->id = id;
setEleID(cube, id);

Objects.push_back(cube);
}
}
Expand All @@ -213,7 +244,7 @@ bool XYY_SceneContent::loadXML(const char * path)
if (lttype == "directional") light = new XYY_LightElement(0);
else if (lttype == "spot") light = new XYY_LightElement(2);
else light = new XYY_LightElement(1);
light->ld_light->position = glm::vec3(atof(ltposx.c_str()), atof(ltposy.c_str()), atof(ltposz.c_str()));
light->ld_light->position = bloc + glm::vec3(atof(ltposx.c_str()), atof(ltposy.c_str()), atof(ltposz.c_str()));


// colorr colorg colorb
Expand All @@ -228,6 +259,12 @@ bool XYY_SceneContent::loadXML(const char * path)
light->setcolor( glm::vec3(atof(colorr.c_str()), atof(colorg.c_str()), atof(colorb.c_str())) );
}

// id
std::string id = "0"; bool _id = false;
if (sonele->Attribute("id")) _id = true, id = sonele->Attribute("id");
light->id = id;
setEleID(light, id);

Lights.push_back(light);
}
}
Expand All @@ -242,18 +279,20 @@ bool XYY_SceneContent::loadXML(const char * path)
// positionx positiony positionz yaw pitch
std::string yaw = "0"; bool _yaw = false;
std::string pitch = "0"; bool _pitch = false;
std::string posx = "0"; bool _posx = false;
std::string posy = "0"; bool _posy = false;
std::string posz = "0"; bool _posz = false;
std::string posx = "10"; bool _posx = false;
std::string posy = "10"; bool _posy = false;
std::string posz = "10"; bool _posz = false;
if (sonele->Attribute("positionx")) _posx = true , posx = sonele->Attribute("positionx");
if (sonele->Attribute("positiony")) _posy = true , posy = sonele->Attribute("positiony");
if (sonele->Attribute("positionz")) _posz = true , posz = sonele->Attribute("positionz");
if (sonele->Attribute("yaw")) _yaw = true, yaw = sonele->Attribute("yaw");
if (sonele->Attribute("pitch")) _pitch = true, pitch = sonele->Attribute("pitch");
XYY_CameraElement * cra = new XYY_CameraElement();
if (_posx || _posy || _posz) cra->position = glm::vec3(atof(posx.c_str()), atof(posy.c_str()), atof(posz.c_str()));
cra->position = bloc + glm::vec3(atof(posx.c_str()), atof(posy.c_str()), atof(posz.c_str()));
if(_yaw) cra->Yaw = atof(yaw.c_str());
if (_pitch) cra->Pitch = atof(pitch.c_str());

Cameras.push_back(cra);


// use
Expand All @@ -264,6 +303,11 @@ bool XYY_SceneContent::loadXML(const char * path)
std::swap( Cameras[Cameras.size() - 1], Cameras[0] );
}

// id
std::string id = "0"; bool _id = false;
if (sonele->Attribute("id")) _id = true, id = sonele->Attribute("id");
cra->id = id;
setEleID(cra, id);

}
}
Expand All @@ -276,8 +320,32 @@ bool XYY_SceneContent::loadXML(const char * path)
if (!path) continue;
XYY_SkyboxElement * skybx = new XYY_SkyboxElement(skypath, defaultskyboxshader);
skybox = skybx;

// id
std::string id = "0"; bool _id = false;
if (elem->Attribute("id")) _id = true, id = elem->Attribute("id");
skybx->id = id;
setEleID(skybx, id);
}
else if (elemName == "scxml")
{
// basex basey basez
std::string basex = "0", basey = "0", basez = "0";
bool _basex = false, _basey = false, _basez = false;
if (elem->Attribute("basex")) _basex = true, basex = elem->Attribute("basex");
if (elem->Attribute("basey")) _basey = true, basey = elem->Attribute("basey");
if (elem->Attribute("basez")) _basez = true, basez = elem->Attribute("basez");

// path
std::string path; bool _path = false;
if (elem->Attribute("path")) _path = true, path = elem->Attribute("path");

if (!_path) continue;

/* 支持 多层XML引入 */
loadXML( path.c_str() , true , bloc + glm::vec3( atof(basex.c_str()) , atof(basey.c_str()) , atof(basez.c_str()) ) );

}
}
// 清理内存
doc.Clear();
Expand Down
Loading

0 comments on commit d426a57

Please sign in to comment.