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 engine $@
|
||||
@echo done
|
||||
|
||||
obj:
|
||||
@$(MAKE) -s -C engine $@
|
||||
|
@ -54,6 +54,9 @@ $(NAME): $(OBJ)
|
||||
@g++ -o $(NAME) $(OBJ) $(LDFLAGS)
|
||||
@echo done
|
||||
|
||||
obj: $(OBJ)
|
||||
@echo done
|
||||
|
||||
clean:
|
||||
-@$(RMSUB) *.o
|
||||
-@$(RMSUB) *.d
|
||||
|
@ -152,6 +152,15 @@ void RenderDevice::pushTransformation(const Vector3& position,
|
||||
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()
|
||||
{
|
||||
glMatrixMode( GL_MODELVIEW);
|
||||
|
@ -45,6 +45,7 @@ public:
|
||||
void setMaterial(Material *);
|
||||
|
||||
void setTexture(unsigned int unit, Texture* texture, bool last = false);
|
||||
void pushAbsoluteTransformation (const Vector3&, const Quaternion&);
|
||||
void pushTransformation (const Vector3&, const Quaternion&);
|
||||
void popTransformation ();
|
||||
void setupProjectionMatrix();
|
||||
|
@ -180,7 +180,7 @@ void ScriptSystem::callFunction(const std::string &name)
|
||||
if (SQ_SUCCEEDED(sq_get(_VM, -2)) )
|
||||
{
|
||||
sq_pushroottable(_VM);
|
||||
if (sq_call(_VM, 1, SQTrue, SQTrue) )
|
||||
sq_call(_VM, 1, SQFalse, SQTrue);
|
||||
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_pushfloat(_VM, value);
|
||||
if (sq_call(_VM, 2, SQTrue, SQTrue) )
|
||||
sq_call(_VM, 2, SQFalse, SQTrue);
|
||||
sq_pop(_VM, 1);
|
||||
}
|
||||
sq_pop(_VM, 1);
|
||||
|
170
engine/main.cpp
170
engine/main.cpp
@ -65,55 +65,75 @@ void shutdownPhysfs()
|
||||
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;
|
||||
cfg.parseFile("options.cfg");
|
||||
|
||||
int width = cfg.get("width", 640);
|
||||
int height = cfg.get("height", 480);
|
||||
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);
|
||||
ref_ptr<FontManager> fontmanager = new FontManager(device);
|
||||
ref_ptr<MeshManager> meshmanager = new MeshManager(device);
|
||||
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();
|
||||
_Window = new RenderWindow();
|
||||
if (_Window->create(width, height, 0, 0, 0, fullscreen) == false)
|
||||
return false;
|
||||
|
||||
setupScriptSystem_Font(scriptsystem, fontmanager);
|
||||
setupScriptSystem_Image(scriptsystem, texturemanager, device);
|
||||
setupScriptSystem_Math(scriptsystem);
|
||||
setupScriptSystem_RigidBody(scriptsystem, simulation);
|
||||
_Device = new RenderDevice(_Window);
|
||||
_FontManager = new FontManager(_Device);
|
||||
_MeshManager = new MeshManager(_Device);
|
||||
_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[] =
|
||||
{ 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);
|
||||
setupScriptSystem_Font(_ScriptSystem, _FontManager);
|
||||
setupScriptSystem_Image(_ScriptSystem, _TextureManager, _Device);
|
||||
setupScriptSystem_Math(_ScriptSystem);
|
||||
setupScriptSystem_RigidBody(_ScriptSystem, _Simulation);
|
||||
|
||||
ref_ptr<Mesh> starMesh = meshmanager->loadMesh("stars.3ds");
|
||||
ref_ptr<Texture> starTexture = texturemanager->loadTexture("stars.png", 0);
|
||||
_ScriptSystem->loadScript("main");
|
||||
_ScriptSystem->callFunction("Initialize");
|
||||
|
||||
ref_ptr<Mesh> nebularMesh = meshmanager->loadMesh("nebular.3ds");
|
||||
ref_ptr<Texture> nebularTexture = texturemanager->loadTexture("nebular.png");
|
||||
_Window->KeySignal.connect(this, &Application::KeySlot);
|
||||
|
||||
_Running = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
if (window.valid() && device.valid())
|
||||
{
|
||||
scriptsystem->loadScript("main");
|
||||
|
||||
camera->setFoV(90.0);
|
||||
camera->setFoV(45.0);
|
||||
camera->setAspectRatio((double)width/(double)height);
|
||||
camera->setNearPlane(1.0);
|
||||
camera->setFarPlane(15000.0);
|
||||
@ -123,31 +143,66 @@ int main(int argc, char **argv)
|
||||
|
||||
//ref_ptr<SceneNode> rootnode(new SceneNode("root node"));
|
||||
|
||||
double _DeltaTime = 0;
|
||||
double _LastTime = glfwGetTime();
|
||||
|
||||
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;
|
||||
|
||||
while (window->isOpen())
|
||||
_DeltaTime = 0;
|
||||
_LastTime = glfwGetTime();
|
||||
|
||||
while (_Window->isOpen() && _Running)
|
||||
{
|
||||
double time = glfwGetTime();
|
||||
_DeltaTime = time - _LastTime;
|
||||
_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);
|
||||
|
||||
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);
|
||||
|
||||
device->pushAbsoluteTransformation(Vector3(), camera->getRotation());
|
||||
|
||||
class RenderState
|
||||
{
|
||||
bool _Blending;
|
||||
GLint _BlendFuncSrc;
|
||||
GLint _BlendFuncDest;
|
||||
|
||||
bool _DepthTest;
|
||||
bool _DepthMask;
|
||||
|
||||
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);
|
||||
|
||||
glMatrixMode ( GL_MODELVIEW );
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
@ -157,9 +212,10 @@ int main(int argc, char **argv)
|
||||
|
||||
device->setTexture(0, starTexture, true);
|
||||
starMesh->render();
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
|
||||
device->popTransformation();
|
||||
*/
|
||||
// device->useShader (program);
|
||||
// device->setTexture (stage, name, texture)
|
||||
// device->clearTextures (stage+1);
|
||||
@ -171,19 +227,31 @@ int main(int argc, char **argv)
|
||||
//device->
|
||||
//model->render();
|
||||
|
||||
simulation->saveStates();
|
||||
simulation->updateSteps(_DeltaTime);
|
||||
while (simulation->step())
|
||||
_Simulation->saveStates();
|
||||
_Simulation->updateSteps(_DeltaTime);
|
||||
while (_Simulation->step())
|
||||
;
|
||||
scriptsystem->callFunction("OnFrame", _DeltaTime);
|
||||
|
||||
device->swap();
|
||||
_ScriptSystem->callFunction("OnFrame", _DeltaTime);
|
||||
|
||||
_Device->swap();
|
||||
}
|
||||
|
||||
scriptsystem->callFunction("Shutdown");
|
||||
|
||||
clog << "--- main loop finished..."<< endlog;
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
initializePhysfs(argv[0]);
|
||||
|
||||
Application app;
|
||||
|
||||
if (app.initialize())
|
||||
{
|
||||
app.run();
|
||||
}
|
||||
app.shutdown();
|
||||
|
||||
shutdownPhysfs();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user