aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/lua_api/load_scene.cpp (renamed from src/client/lua_api/load_core.cpp)2
-rw-r--r--src/client/lua_api/load_scene.hpp (renamed from src/client/lua_api/load_core.hpp)6
-rw-r--r--src/client/lua_api/phys/bphysbox.cpp3
-rw-r--r--src/client/lua_api/phys/bphysmodel.cpp3
-rw-r--r--src/client/main.cpp222
-rw-r--r--src/client/menuhandeler.cpp3
6 files changed, 75 insertions, 164 deletions
diff --git a/src/client/lua_api/load_core.cpp b/src/client/lua_api/load_scene.cpp
index 4a74d39..285cba0 100644
--- a/src/client/lua_api/load_core.cpp
+++ b/src/client/lua_api/load_scene.cpp
@@ -18,7 +18,7 @@ using namespace irr;
extern IrrlichtDevice* device;
-void load_corefuncs(lua_State* L){
+void load_scenefuncs(lua_State* L){
icamera_register(L,device);
imesh_register(L,device);
ilight_register(L,device);
diff --git a/src/client/lua_api/load_core.hpp b/src/client/lua_api/load_scene.hpp
index b3b42ff..7602d08 100644
--- a/src/client/lua_api/load_core.hpp
+++ b/src/client/lua_api/load_scene.hpp
@@ -1,5 +1,5 @@
-#ifndef __H_loadcore
-#define __H_loadcore
+#ifndef __H_loadscene
+#define __H_loadscene
#include <stdio.h>
#include <stdlib.h>
#include <vector>
@@ -10,5 +10,5 @@ extern "C" {
}
#include <irrlicht.h>
-void load_corefuncs(lua_State* L);
+void load_scenefuncs(lua_State* L);
#endif
diff --git a/src/client/lua_api/phys/bphysbox.cpp b/src/client/lua_api/phys/bphysbox.cpp
index 80cd2eb..a03b488 100644
--- a/src/client/lua_api/phys/bphysbox.cpp
+++ b/src/client/lua_api/phys/bphysbox.cpp
@@ -5,6 +5,7 @@
#include <memory>
#include <map>
#include <functional>
+#include <list>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
@@ -24,7 +25,7 @@ using namespace video;
extern IrrlichtDevice* device;
extern btDiscreteDynamicsWorld* World;
-extern core::list<btRigidBody*> Objects;
+extern std::list<btRigidBody*> Objects;
static LBPhysNode* checkisbphysbox(lua_State* L, int index){
void* ud = luaL_checkudata(L,index,"phys.physbox");
diff --git a/src/client/lua_api/phys/bphysmodel.cpp b/src/client/lua_api/phys/bphysmodel.cpp
index 7bdc483..b76b336 100644
--- a/src/client/lua_api/phys/bphysmodel.cpp
+++ b/src/client/lua_api/phys/bphysmodel.cpp
@@ -5,6 +5,7 @@
#include <memory>
#include <map>
#include <functional>
+#include <list>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
@@ -25,7 +26,7 @@ using namespace video;
extern IrrlichtDevice* device;
extern btDiscreteDynamicsWorld* World;
-extern core::list<btRigidBody*> Objects;
+extern std::list<btRigidBody*> Objects;
static LBPhysNode* checkisbphysmodel(lua_State* L, int index){
void* ud = luaL_checkudata(L,index,"phys.physmodel");
diff --git a/src/client/main.cpp b/src/client/main.cpp
index 52de76f..763c9f3 100644
--- a/src/client/main.cpp
+++ b/src/client/main.cpp
@@ -7,6 +7,8 @@ extern "C" {
}
#include <irrlicht.h>
+#include <chrono>
+
#include <btBulletDynamicsCommon.h>
#include <cstdlib>
@@ -14,139 +16,65 @@ extern "C" {
#include "menuhandeler.hpp"
#include "lua_api/load_gui.hpp"
#include "lua_api/load_game.hpp"
-#include "lua_api/load_core.hpp"
+#include "lua_api/load_scene.hpp"
#include "lua_api/load_phys.hpp"
#include "callbackhandeler.hpp"
+#include "../shared/lua_api/common.h"
+#include "../shared/lua_api/load_net.hpp"
+#include "../shared/phys/physcommon.hpp"
+
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
+using namespace std::chrono;
-btDiscreteDynamicsWorld* World;
-core::list<btRigidBody*> Objects;
-
-void loadLLibs(lua_State* L){
- luaopen_base(L);
- luaopen_table(L);
- luaopen_io(L);
- luaopen_string(L);
- luaopen_math(L);
-}
+//btDiscreteDynamicsWorld* World;
+//irr::core::list<btRigidBody*> Objects;
lua_State* L;
IrrlichtDevice* device;
void loadIrrLibs(lua_State* L, IrrlichtDevice* device){
- printf("Loading guifuncs...\n");
- load_guifuncs(L);
- load_gamefuncs(L);
- load_corefuncs(L);
- load_physfuncs(L);
+ printf("Loading guifuncs...\n");
+ load_guifuncs(L);
+ load_gamefuncs(L);
+ load_scenefuncs(L);
+ load_physfuncs(L);
}
static int GetRandInt(int TMax) { return rand() % TMax; }
+void RemoveISceneNode(btRigidBody* rb){
+ ISceneNode *Node = static_cast<ISceneNode*>(rb->getUserPointer());
+ Node->remove();
+}
+/*
// Removes all objects from the world
-void ClearObjects() {
+void ClearObjects(btDiscreteDynamicsWorld* wr, core::list<btRigidBody*> objs, void(*f)(btRigidBody*)) {
- for(list<btRigidBody *>::Iterator Iterator = Objects.begin(); Iterator != Objects.end(); ++Iterator) {
+ for(list<btRigidBody *>::Iterator Iterator = objs.begin(); Iterator != objs.end(); ++Iterator) {
btRigidBody *Object = *Iterator;
- printf("Found an object to clean:%p\n",Object);
-
+ if(f){
+ (*f)(Object);
+ }
// Delete irrlicht node
ISceneNode *Node = static_cast<ISceneNode *>(Object->getUserPointer());
- printf("got node\n");
Node->remove();
- printf("removed node\n");
+
// Remove the object from the world
- World->removeRigidBody(Object);
- printf("removed rigidbody\n");
- printf("right before delete, object is %p\n",Object);
+ wr->removeRigidBody(Object);
delete Object;
- printf("deleted object\n");
}
-
- Objects.clear();
+ objs.clear();
}
+*/
-// Create a box rigid body
-// void CreateBox(ISceneManager* irrScene, const btVector3 &TPosition, const core::vector3df &TScale, btScalar TMass) {
-//
-// // Create an Irrlicht cube
-// scene::ISceneNode *Node = irrScene->addCubeSceneNode(1.0f);
-// Node->setScale(TScale);
-//
-// Node->setMaterialFlag(video::EMF_LIGHTING, 1);
-// Node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
-// //Node->setMaterialTexture(0, irrDriver->getTexture("rust0.jpg"));
-//
-// // Set the initial position of the object
-// btTransform Transform;
-// Transform.setIdentity();
-// Transform.setOrigin(TPosition);
-//
-// // Give it a default MotionState
-// btDefaultMotionState *MotionState = new btDefaultMotionState(Transform);
-//
-// // Create the shape
-// btVector3 HalfExtents(TScale.X * 0.5f, TScale.Y * 0.5f, TScale.Z * 0.5f);
-// btCollisionShape *Shape = new btBoxShape(HalfExtents);
-//
-// // Add mass
-// btVector3 LocalInertia;
-// Shape->calculateLocalInertia(TMass, LocalInertia);
-//
-// // Create the rigid body object
-// btRigidBody *RigidBody = new btRigidBody(TMass, MotionState, Shape, LocalInertia);
-//
-// // Store a pointer to the irrlicht node so we can update it later
-// RigidBody->setUserPointer((void *)(Node));
-//
-// // Add it to the world
-// World->addRigidBody(RigidBody);
-// Objects.push_back(RigidBody);
-// }
-//
-// // Create a sphere rigid body
-// void CreateSphere(ISceneManager* irrScene, const btVector3 &TPosition, btScalar TRadius, btScalar TMass) {
-//
-// // Create an Irrlicht sphere
-// scene::ISceneNode *Node = irrScene->addSphereSceneNode(TRadius, 32);
-// Node->setMaterialFlag(video::EMF_LIGHTING, 1);
-// Node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
-// //Node->setMaterialTexture(0, irrDriver->getTexture("ice0.jpg"));
-//
-// // Set the initial position of the object
-// btTransform Transform;
-// Transform.setIdentity();
-// Transform.setOrigin(TPosition);
-//
-// // Give it a default MotionState
-// btDefaultMotionState *MotionState = new btDefaultMotionState(Transform);
-//
-// // Create the shape
-// btCollisionShape *Shape = new btSphereShape(TRadius);
-//
-// // Add mass
-// btVector3 LocalInertia;
-// Shape->calculateLocalInertia(TMass, LocalInertia);
-//
-// // Create the rigid body object
-// btRigidBody *RigidBody = new btRigidBody(TMass, MotionState, Shape, LocalInertia);
-//
-// // Store a pointer to the irrlicht node so we can update it later
-// RigidBody->setUserPointer((void *)(Node));
-//
-// // Add it to the world
-// World->addRigidBody(RigidBody);
-// Objects.push_back(RigidBody);
-// }
-//
-// // Converts a quaternion to an euler angle
+// Converts a quaternion to an euler angle
void QuaternionToEuler(const btQuaternion &TQuat, btVector3 &TEuler) {
btScalar W = TQuat.getW();
btScalar X = TQuat.getX();
@@ -163,19 +91,9 @@ void QuaternionToEuler(const btQuaternion &TQuat, btVector3 &TEuler) {
TEuler *= core::RADTODEG;
}
-// Runs the physics simulation.
-// - TDeltaTime tells the simulation how much time has passed since the last frame so the simulation can run independently of the frame rate.
-void UpdatePhysics(u32 TDeltaTime) {
-
- World->stepSimulation(TDeltaTime * 0.002f, 60);
-
- btRigidBody *TObject;
- // Relay the object's orientation to irrlicht
- for(core::list<btRigidBody *>::Iterator it = Objects.begin(); it != Objects.end(); ++it) {
-
+void UpdateElement(btRigidBody* TObject){
//UpdateRender(*Iterator);
- scene::ISceneNode *Node = static_cast<scene::ISceneNode *>((*it)->getUserPointer());
- TObject = *it;
+ scene::ISceneNode *Node = static_cast<scene::ISceneNode *>((TObject)->getUserPointer());
// Set position
btVector3 Point = TObject->getCenterOfMassPosition();
@@ -185,20 +103,25 @@ void UpdatePhysics(u32 TDeltaTime) {
btVector3 EulerRotation;
QuaternionToEuler(TObject->getOrientation(), EulerRotation);
Node->setRotation(core::vector3df(EulerRotation[0], EulerRotation[1], EulerRotation[2]));
-
- }
}
+/*
+// Runs the physics simulation.
+// - TDeltaTime tells the simulation how much time has passed since the last frame so the simulation can run independently of the frame rate. Optionally pass in an argument that will be called on every rigidbody in the world
+void UpdatePhysics(double TDeltaTime, void(*f)(btRigidBody*)) {
-// Creates a base box
-void CreateStartScene(ISceneManager* smgr) {
+ World->stepSimulation(TDeltaTime * 0.02f, 60);
- ClearObjects();
- //CreateBox(smgr,btVector3(0.0f, 0.0f, 0.0f), core::vector3df(10.0f, 0.5f, 10.0f), 0.0f);
+ // Relay the object's orientation to irrlicht
+ for(core::list<btRigidBody *>::Iterator it = Objects.begin(); it != Objects.end(); ++it) {
+ (*f)(*it);
+ }
}
+*/
int main(int argc, char *argv[]){
- printf("Brok[en]gine");
+ printf("Brok[en]gine Client");
// Initialize bullet
+ /*
btBroadphaseInterface *BroadPhase = new btAxisSweep3(btVector3(-1000, -1000, -1000), btVector3(1000, 1000, 1000));
printf("Broadphase\n");
btDefaultCollisionConfiguration *CollisionConfiguration = new btDefaultCollisionConfiguration();
@@ -209,6 +132,9 @@ int main(int argc, char *argv[]){
printf("Solver\n");
World = new btDiscreteDynamicsWorld(Dispatcher, BroadPhase, Solver, CollisionConfiguration);
printf("Physics world init ok.\n");
+ */
+ phys_genesis();
+
//Create a new lua state, this gets shared everywhere
lua_State *state = luaL_newstate();
L = state;
@@ -220,6 +146,7 @@ int main(int argc, char *argv[]){
return 1;
//Loads libraries for interfaceing with irrlicht
loadIrrLibs(state,device);
+ loadNetLibs(state);
printf("Loadded irr libs...\n");
//Sets the global event handeler
GlobalEventReceiver ger = GlobalEventReceiver(device);
@@ -240,44 +167,22 @@ int main(int argc, char *argv[]){
IGUIEnvironment* guienv = device->getGUIEnvironment();
ITimer* irrTimer = device->getTimer();
- device->setWindowCaption(L"Bork[en]gine Demo");
-
- /*
- CreateBox(smgr,
- btVector3(
- GetRandInt(10) - 5.0f, 7.0f,
- GetRandInt(10) - 5.0f),
- core::vector3df(
- GetRandInt(3) + 0.5f,
- GetRandInt(3) + 0.5f,
- GetRandInt(3) + 0.5f),
- 1.0f);
- CreateBox(smgr,
- btVector3(0,0,0),
- core::vector3df(10,10,10),
- 0.0f);
- CreateSphere(smgr,
- btVector3(
- GetRandInt(10) - 5.0f, 7.0f,
- GetRandInt(10) - 5.0f),
- GetRandInt(5) / 5.0f + 0.2f, 1.0f);
- */
-
- //guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
- // rect<s32>(10,10,260,22), true);
- printf("Abbout to add camera\n");
- //smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
- //smgr->addCameraSceneNodeMaya();
+ device->setWindowCaption(L"Bork[en]gine Client");
printf("Everything registered, about to start running device!\n");
- u32 TimeStamp = irrTimer->getTime(), DeltaTime = 0;
+ //u32 TimeStamp = irrTimer->getTime(), DeltaTime = 0;
+ //high_resolution_clock::time_point t1 = high_resolution_clock::now();
while(device->run()){
- if(device->isWindowActive()){
- DeltaTime = irrTimer->getTime() - TimeStamp;
- TimeStamp = irrTimer->getTime();
- UpdatePhysics(DeltaTime);
+ gameloop_net(L);
+ gameloop_phys(UpdateElement);
+ if(device->isWindowActive()){
+ //high_resolution_clock::time_point now = high_resolution_clock::now();
+ //duration<double> delta = now-t1;
+ //double steps = delta.count() * 100;
+ //UpdatePhysics(steps,UpdateElement);
+ //t1 = now;
driver->beginScene(true, true, SColor(255,100,101,140));
@@ -294,10 +199,12 @@ int main(int argc, char *argv[]){
lua_call(state,0,0);
lua_pop(state,2);
}
- printf("Claoseing lua state...\n");
+ printf("Closeing lua state...\n");
//lua_close(state);
- printf("clearing objects...\n");
- ClearObjects(); //Clearing objects must be done after we droped the device.
+ //printf("clearing objects...\n");
+ //ClearObjects(World,Objects,RemoveISceneNode); //Clearing objects must be done after we droped the device.
+ phys_shutdown(RemoveISceneNode);
+ /*
printf("cleared objects\n");
delete BroadPhase;
printf("deleted broadphase\n");
@@ -310,6 +217,7 @@ int main(int argc, char *argv[]){
delete World; //Muah ha ha
printf("deleted world\n");
+ */
device->drop();
printf("droped device\n");
diff --git a/src/client/menuhandeler.cpp b/src/client/menuhandeler.cpp
index 830c695..53d38cc 100644
--- a/src/client/menuhandeler.cpp
+++ b/src/client/menuhandeler.cpp
@@ -15,7 +15,8 @@ using namespace io;
using namespace gui;
void loadMenu(const char* name, IrrlichtDevice* device){
-
+ IGUIEnvironment* env = device->getGUIEnvironment();
+ IGUIWindow* window = env->addWindow(rect<s32>(0,0,200,200),true,L"Menu",0,-1);
}
void showMenu(const char* name, IrrlichtDevice* device){