-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.cpp
More file actions
96 lines (72 loc) · 2.41 KB
/
Copy pathmain.cpp
File metadata and controls
96 lines (72 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "sdk/amxxmodule.h"
#include <btBulletDynamicsCommon.h>
#include <stdio.h>
#include <map>
#include "object.h"
#include "model.h"
#include "debug.h"
//#define BULLET_TRIANGLE_COLLISION 1
#include <BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h>
#define BMOD_GRAVITY -525 //-10m/s^2 -> -1000cm/s^2 -> convert to game units (1/1.905f)
//expecting min 10 FPS
int g_bt_max_ssteps = 6;
float g_bt_ftstep = 1.0 / 60;
char g_game_dir[64];
char g_bspname[260];
std::map<int, bmodObject*> g_bmod_objects;
extern AMX_NATIVE_INFO amxxfunctions[];
//shitload of bullet pointers
btBroadphaseInterface* g_bt_broadphase;
btDefaultCollisionConfiguration* g_bt_collisionConfiguration;
btCollisionDispatcher* g_bt_dispatcher;
btSequentialImpulseConstraintSolver* g_bt_solver;
btDiscreteDynamicsWorld* g_bt_dynamicsWorld;
void OnAmxxAttach() {
MF_AddNatives(amxxfunctions);
GET_GAME_DIR(g_game_dir);
//shitload of bullet init stuff
g_bt_broadphase = new btDbvtBroadphase();
g_bt_collisionConfiguration = new btDefaultCollisionConfiguration();
g_bt_dispatcher = new btCollisionDispatcher(g_bt_collisionConfiguration);
g_bt_solver = new btSequentialImpulseConstraintSolver;
g_bt_dynamicsWorld = new btDiscreteDynamicsWorld(g_bt_dispatcher, g_bt_broadphase, g_bt_solver, g_bt_collisionConfiguration);
g_bt_dynamicsWorld->setGravity(btVector3(0, 0, BMOD_GRAVITY));
btGImpactCollisionAlgorithm::registerAlgorithm(g_bt_dispatcher);
reg_debug_cmds();
MF_Log("attached");
RETURN_META(MRES_IGNORED);
}
void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) {
sprintf(g_bspname, "maps/%s.bsp", STRING(gpGlobals->mapname));
MF_Log("activated");
RETURN_META(MRES_IGNORED);
}
void StartFrame() {
static float oldtime = 0;
float newtime = g_engfuncs.pfnTime();
//step it
g_bt_dynamicsWorld->stepSimulation(newtime - oldtime, g_bt_max_ssteps, g_bt_ftstep);
oldtime = newtime;
RETURN_META(MRES_IGNORED);
}
void ServerDeactivate_Post() {
//unload objects
for(std::map<int, bmodObject*>::iterator it = g_bmod_objects.begin(); it != g_bmod_objects.end(); ++it) {
delete it->second;
}
g_bmod_objects.clear();
//clear models
clearModels();
MF_Log("deactivated");
RETURN_META(MRES_IGNORED);
}
void OnAmxxDetach() {
//unload bullet stuff
delete g_bt_dynamicsWorld;
delete g_bt_solver;
delete g_bt_collisionConfiguration;
delete g_bt_dispatcher;
delete g_bt_broadphase;
MF_Log("detached");
RETURN_META(MRES_IGNORED);
}