some cleanup, fixed memory leak in scripting
This commit is contained in:
parent
219d5743b8
commit
77504c68f3
3
Makefile
3
Makefile
@ -14,3 +14,6 @@ all clean:
|
|||||||
@$(MAKE) -s -C tinyxml $@
|
@$(MAKE) -s -C tinyxml $@
|
||||||
@$(MAKE) -s -C engine $@
|
@$(MAKE) -s -C engine $@
|
||||||
@echo done
|
@echo done
|
||||||
|
|
||||||
|
obj:
|
||||||
|
@$(MAKE) -s -C engine $@
|
||||||
|
@ -54,6 +54,9 @@ $(NAME): $(OBJ)
|
|||||||
@g++ -o $(NAME) $(OBJ) $(LDFLAGS)
|
@g++ -o $(NAME) $(OBJ) $(LDFLAGS)
|
||||||
@echo done
|
@echo done
|
||||||
|
|
||||||
|
obj: $(OBJ)
|
||||||
|
@echo done
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-@$(RMSUB) *.o
|
-@$(RMSUB) *.o
|
||||||
-@$(RMSUB) *.d
|
-@$(RMSUB) *.d
|
||||||
|
@ -152,6 +152,15 @@ void RenderDevice::pushTransformation(const Vector3& position,
|
|||||||
glMultMatrixd( ( GLdouble * ) &m.m );
|
glMultMatrixd( ( GLdouble * ) &m.m );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderDevice::pushAbsoluteTransformation(const Vector3& position,
|
||||||
|
const Quaternion& orientation)
|
||||||
|
{
|
||||||
|
glMatrixMode( GL_MODELVIEW);
|
||||||
|
glPushMatrix();
|
||||||
|
Matrix4x4 m(orientation, position);
|
||||||
|
glLoadMatrixd( ( GLdouble * ) &m.m );
|
||||||
|
}
|
||||||
|
|
||||||
void RenderDevice::popTransformation()
|
void RenderDevice::popTransformation()
|
||||||
{
|
{
|
||||||
glMatrixMode( GL_MODELVIEW);
|
glMatrixMode( GL_MODELVIEW);
|
||||||
|
@ -45,6 +45,7 @@ public:
|
|||||||
void setMaterial(Material *);
|
void setMaterial(Material *);
|
||||||
|
|
||||||
void setTexture(unsigned int unit, Texture* texture, bool last = false);
|
void setTexture(unsigned int unit, Texture* texture, bool last = false);
|
||||||
|
void pushAbsoluteTransformation (const Vector3&, const Quaternion&);
|
||||||
void pushTransformation (const Vector3&, const Quaternion&);
|
void pushTransformation (const Vector3&, const Quaternion&);
|
||||||
void popTransformation ();
|
void popTransformation ();
|
||||||
void setupProjectionMatrix();
|
void setupProjectionMatrix();
|
||||||
|
@ -180,7 +180,7 @@ void ScriptSystem::callFunction(const std::string &name)
|
|||||||
if (SQ_SUCCEEDED(sq_get(_VM, -2)) )
|
if (SQ_SUCCEEDED(sq_get(_VM, -2)) )
|
||||||
{
|
{
|
||||||
sq_pushroottable(_VM);
|
sq_pushroottable(_VM);
|
||||||
if (sq_call(_VM, 1, SQTrue, SQTrue) )
|
sq_call(_VM, 1, SQFalse, SQTrue);
|
||||||
sq_pop(_VM, 1);
|
sq_pop(_VM, 1);
|
||||||
}
|
}
|
||||||
sq_pop(_VM, 1);
|
sq_pop(_VM, 1);
|
||||||
@ -195,7 +195,7 @@ void ScriptSystem::callFunction(const std::string &name, double value)
|
|||||||
{
|
{
|
||||||
sq_pushroottable(_VM);
|
sq_pushroottable(_VM);
|
||||||
sq_pushfloat(_VM, value);
|
sq_pushfloat(_VM, value);
|
||||||
if (sq_call(_VM, 2, SQTrue, SQTrue) )
|
sq_call(_VM, 2, SQFalse, SQTrue);
|
||||||
sq_pop(_VM, 1);
|
sq_pop(_VM, 1);
|
||||||
}
|
}
|
||||||
sq_pop(_VM, 1);
|
sq_pop(_VM, 1);
|
||||||
|
182
engine/main.cpp
182
engine/main.cpp
@ -65,55 +65,75 @@ void shutdownPhysfs()
|
|||||||
PHYSFS_deinit();
|
PHYSFS_deinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
class Application : public sigslot::has_slots<>
|
||||||
{
|
{
|
||||||
initializePhysfs(argv[0]);
|
bool _Running;
|
||||||
|
double _DeltaTime;
|
||||||
|
double _LastTime;
|
||||||
|
|
||||||
|
void KeySlot(int key, int action)
|
||||||
|
{
|
||||||
|
if (key == GLFW_KEY_ESC && action == GLFW_RELEASE)
|
||||||
|
quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
ref_ptr<RenderWindow> _Window;
|
||||||
|
ref_ptr<RenderDevice> _Device;
|
||||||
|
ref_ptr<FontManager> _FontManager;
|
||||||
|
ref_ptr<MeshManager> _MeshManager;
|
||||||
|
ref_ptr<TextureManager> _TextureManager;
|
||||||
|
ref_ptr<ScriptSystem> _ScriptSystem;
|
||||||
|
ref_ptr<ShaderManager> _ShaderManager;
|
||||||
|
ref_ptr<RigidBodySimulation> _Simulation;
|
||||||
|
ref_ptr<ModelManager> _ModelManager;
|
||||||
|
ref_ptr<Camera> _Camera;
|
||||||
|
ref_ptr<RenderQueue> _RenderQueue;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
bool initialize()
|
||||||
|
{
|
||||||
CfgParser cfg;
|
CfgParser cfg;
|
||||||
cfg.parseFile("options.cfg");
|
cfg.parseFile("options.cfg");
|
||||||
|
|
||||||
int width = cfg.get("width", 640);
|
int width = cfg.get("width", 640);
|
||||||
int height = cfg.get("height", 480);
|
int height = cfg.get("height", 480);
|
||||||
bool fullscreen = cfg.get("fullscreen", false);
|
bool fullscreen = cfg.get("fullscreen", false);
|
||||||
ref_ptr<RenderWindow> window = new RenderWindow();
|
|
||||||
window->create(width, height, 0, 0, 0, fullscreen);
|
|
||||||
|
|
||||||
ref_ptr<RenderDevice> device = new RenderDevice(window);
|
_Window = new RenderWindow();
|
||||||
ref_ptr<FontManager> fontmanager = new FontManager(device);
|
if (_Window->create(width, height, 0, 0, 0, fullscreen) == false)
|
||||||
ref_ptr<MeshManager> meshmanager = new MeshManager(device);
|
return false;
|
||||||
ref_ptr<TextureManager> texturemanager = new TextureManager();
|
|
||||||
ref_ptr<ScriptSystem> scriptsystem = new ScriptSystem();
|
|
||||||
ref_ptr<ShaderManager> shadermanager = new ShaderManager(window);
|
|
||||||
ref_ptr<RigidBodySimulation> simulation = new RigidBodySimulation(scriptsystem);
|
|
||||||
ref_ptr<ModelManager> modelmanager = new ModelManager (texturemanager, shadermanager, meshmanager);
|
|
||||||
ref_ptr<Camera> camera = new Camera();
|
|
||||||
ref_ptr<RenderQueue> queue = new RenderQueue();
|
|
||||||
|
|
||||||
setupScriptSystem_Font(scriptsystem, fontmanager);
|
_Device = new RenderDevice(_Window);
|
||||||
setupScriptSystem_Image(scriptsystem, texturemanager, device);
|
_FontManager = new FontManager(_Device);
|
||||||
setupScriptSystem_Math(scriptsystem);
|
_MeshManager = new MeshManager(_Device);
|
||||||
setupScriptSystem_RigidBody(scriptsystem, simulation);
|
_TextureManager = new TextureManager();
|
||||||
|
_ScriptSystem = new ScriptSystem();
|
||||||
|
_ShaderManager = new ShaderManager(_Window);
|
||||||
|
_Simulation = new RigidBodySimulation(_ScriptSystem);
|
||||||
|
_ModelManager = new ModelManager (_TextureManager, _ShaderManager, _MeshManager);
|
||||||
|
_Camera = new Camera();
|
||||||
|
_RenderQueue = new RenderQueue();
|
||||||
|
|
||||||
GLfloat mat_specular[] =
|
setupScriptSystem_Font(_ScriptSystem, _FontManager);
|
||||||
{ 1.0, 1.0, 1.0, 1.0 };
|
setupScriptSystem_Image(_ScriptSystem, _TextureManager, _Device);
|
||||||
GLfloat mat_shininess[] =
|
setupScriptSystem_Math(_ScriptSystem);
|
||||||
{ 2.0 };
|
setupScriptSystem_RigidBody(_ScriptSystem, _Simulation);
|
||||||
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_specular);
|
|
||||||
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_specular);
|
|
||||||
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
|
||||||
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
|
|
||||||
|
|
||||||
ref_ptr<Mesh> starMesh = meshmanager->loadMesh("stars.3ds");
|
_ScriptSystem->loadScript("main");
|
||||||
ref_ptr<Texture> starTexture = texturemanager->loadTexture("stars.png", 0);
|
_ScriptSystem->callFunction("Initialize");
|
||||||
|
|
||||||
ref_ptr<Mesh> nebularMesh = meshmanager->loadMesh("nebular.3ds");
|
_Window->KeySignal.connect(this, &Application::KeySlot);
|
||||||
ref_ptr<Texture> nebularTexture = texturemanager->loadTexture("nebular.png");
|
|
||||||
|
|
||||||
|
_Running = true;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/*
|
||||||
if (window.valid() && device.valid())
|
if (window.valid() && device.valid())
|
||||||
{
|
{
|
||||||
scriptsystem->loadScript("main");
|
|
||||||
|
|
||||||
camera->setFoV(90.0);
|
camera->setFoV(45.0);
|
||||||
camera->setAspectRatio((double)width/(double)height);
|
camera->setAspectRatio((double)width/(double)height);
|
||||||
camera->setNearPlane(1.0);
|
camera->setNearPlane(1.0);
|
||||||
camera->setFarPlane(15000.0);
|
camera->setFarPlane(15000.0);
|
||||||
@ -123,43 +143,79 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
//ref_ptr<SceneNode> rootnode(new SceneNode("root node"));
|
//ref_ptr<SceneNode> rootnode(new SceneNode("root node"));
|
||||||
|
|
||||||
double _DeltaTime = 0;
|
|
||||||
double _LastTime = glfwGetTime();
|
|
||||||
|
|
||||||
ref_ptr<Model> model = modelmanager->loadModel("combat");
|
ref_ptr<Model> model = modelmanager->loadModel("combat");
|
||||||
scriptsystem->callFunction("Initialize");
|
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
void shutdown()
|
||||||
|
{
|
||||||
|
_ScriptSystem->callFunction("Shutdown");
|
||||||
|
}
|
||||||
|
|
||||||
|
void quit()
|
||||||
|
{
|
||||||
|
_Running = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void run()
|
||||||
|
{
|
||||||
clog << "--- starting main loop..."<< endlog;
|
clog << "--- starting main loop..."<< endlog;
|
||||||
|
|
||||||
while (window->isOpen())
|
_DeltaTime = 0;
|
||||||
|
_LastTime = glfwGetTime();
|
||||||
|
|
||||||
|
while (_Window->isOpen() && _Running)
|
||||||
{
|
{
|
||||||
double time = glfwGetTime();
|
double time = glfwGetTime();
|
||||||
_DeltaTime = time - _LastTime;
|
_DeltaTime = time - _LastTime;
|
||||||
_LastTime = time;
|
_LastTime = time;
|
||||||
|
|
||||||
device->clear();
|
_Device->clear();
|
||||||
|
/*
|
||||||
|
camera->setRotation(Quaternion(Vector3(0.0, 1.0, 0.0), fmod(time
|
||||||
|
/5.0, 6.2)));
|
||||||
device->begin3D(camera);
|
device->begin3D(camera);
|
||||||
|
|
||||||
queue->clear();
|
queue->clear();
|
||||||
queue->addOpaqueItem(model, Vector3(10.0, 0.0, 0.0), Quaternion(Vector3(0.0,1.0,0.0), fmod(time, 3)));
|
queue->addOpaqueItem(model, Vector3(10.0, 0.0, 0.0), Quaternion());
|
||||||
queue->render(device);
|
queue->render(device);
|
||||||
|
|
||||||
|
device->pushAbsoluteTransformation(Vector3(), camera->getRotation());
|
||||||
|
|
||||||
glMatrixMode ( GL_MODELVIEW );
|
class RenderState
|
||||||
glPushMatrix();
|
{
|
||||||
glLoadIdentity();
|
bool _Blending;
|
||||||
glEnable ( GL_BLEND );
|
GLint _BlendFuncSrc;
|
||||||
glBlendFunc ( GL_ONE, GL_ONE );
|
GLint _BlendFuncDest;
|
||||||
glEnable ( GL_DEPTH_TEST );
|
|
||||||
glDepthMask ( GL_FALSE );
|
bool _DepthTest;
|
||||||
glDisable ( GL_LIGHTING );
|
bool _DepthMask;
|
||||||
glColor4d ( 1.0f, 1.0f, 1.0f, 1.0f );
|
|
||||||
|
bool _Lighting;
|
||||||
|
};
|
||||||
|
GLfloat mat_specular[] =
|
||||||
|
{ 1.0, 1.0, 1.0, 1.0 };
|
||||||
|
GLfloat mat_shininess[] =
|
||||||
|
{ 2.0 };
|
||||||
|
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_specular);
|
||||||
|
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_specular);
|
||||||
|
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
||||||
|
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
|
||||||
|
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_ONE, GL_ONE);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glDepthMask(GL_FALSE);
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
glColor4d( 1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
device->setTexture(0, starTexture, true);
|
device->setTexture(0, starTexture, true);
|
||||||
starMesh->render();
|
starMesh->render();
|
||||||
glDisable ( GL_BLEND );
|
|
||||||
|
|
||||||
|
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
device->popTransformation();
|
||||||
|
*/
|
||||||
// device->useShader (program);
|
// device->useShader (program);
|
||||||
// device->setTexture (stage, name, texture)
|
// device->setTexture (stage, name, texture)
|
||||||
// device->clearTextures (stage+1);
|
// device->clearTextures (stage+1);
|
||||||
@ -171,19 +227,31 @@ int main(int argc, char **argv)
|
|||||||
//device->
|
//device->
|
||||||
//model->render();
|
//model->render();
|
||||||
|
|
||||||
simulation->saveStates();
|
_Simulation->saveStates();
|
||||||
simulation->updateSteps(_DeltaTime);
|
_Simulation->updateSteps(_DeltaTime);
|
||||||
while (simulation->step())
|
while (_Simulation->step())
|
||||||
;
|
;
|
||||||
scriptsystem->callFunction("OnFrame", _DeltaTime);
|
|
||||||
|
|
||||||
device->swap();
|
_ScriptSystem->callFunction("OnFrame", _DeltaTime);
|
||||||
|
|
||||||
|
_Device->swap();
|
||||||
}
|
}
|
||||||
|
|
||||||
scriptsystem->callFunction("Shutdown");
|
|
||||||
|
|
||||||
clog << "--- main loop finished..."<< endlog;
|
clog << "--- main loop finished..."<< endlog;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
initializePhysfs(argv[0]);
|
||||||
|
|
||||||
|
Application app;
|
||||||
|
|
||||||
|
if (app.initialize())
|
||||||
|
{
|
||||||
|
app.run();
|
||||||
|
}
|
||||||
|
app.shutdown();
|
||||||
|
|
||||||
shutdownPhysfs();
|
shutdownPhysfs();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user