Skip to content

Commit d21043c

Browse files
Add line segement collisions (#75)
* adds mesh debug shapes * adds tests on non-main branches * stable rectangles --------- Co-authored-by: harveydevereux <harveydevereux@googlemail.com> Former-commit-id: f709bce
1 parent f84eec3 commit d21043c

30 files changed

Lines changed: 2544 additions & 274 deletions
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363

6464
- name: linux-X-windows
6565
run: |
66-
./dependencies.sh -w && ./build.sh -w -t -d -r
66+
./dependencies.sh -w && ./build.sh -w -d -r
6767
mkdir windowsbuild
6868
cp build/libHop.a windowsbuild/
6969
cp -r include windowsbuild/

.github/workflows/unit-tests.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Hop
2+
3+
on:
4+
push:
5+
branches-ignore: 'main'
6+
tags: 'v*'
7+
paths-ignore:
8+
- 'doc/**'
9+
- '.github/**'
10+
pull_request:
11+
workflow_dispatch:
12+
13+
jobs:
14+
linuxXlinux:
15+
runs-on: ubuntu-20.04
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- name: Install dependencies
21+
run: sudo apt-get update && sudo apt-get install -y build-essential xorg-dev mesa-common-dev libx11-dev libxrandr-dev libgl1-mesa-dev libglu1-mesa-dev libfreetype6-dev libopenal-dev libsndfile1-dev libudev-dev libxinerama-dev libxcursor-dev
22+
23+
- name: linux-linux
24+
run: |
25+
./dependencies.sh && ./build.sh -t -d -r
26+
27+
- name: Tests
28+
working-directory: ${{github.workspace}}/build
29+
# Execute tests defined by the CMake configuration.
30+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
31+
run: ctest

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ if (RELEASE)
4444
if (ANDROID)
4545
# GOOGLE!! (Release is not a thing pos ndk 23 apparently..)
4646
add_compile_definitions(BUILD_TYPE="MinSizeRel")
47-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-trapping-math -fno-rounding-math -fno-signed-zeros -funsafe-math-optimizations")
47+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-trapping-math -fno-rounding-math -fno-signed-zeros")
4848
else()
4949
add_compile_definitions(BUILD_TYPE="Release")
50-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-trapping-math -fno-rounding-math -fno-signaling-nans -fno-signed-zeros -funsafe-math-optimizations")
50+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-trapping-math -fno-rounding-math -fno-signaling-nans -fno-signed-zeros")
5151
endif()
5252
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -O3")
5353

@@ -184,6 +184,8 @@ IF (TEST_SUITE)
184184
"src/World/mapFile.cpp"
185185
)
186186

187+
target_compile_definitions(testSuite PUBLIC GLSL_VERSION="330")
188+
187189
target_link_libraries(testSuite stduuid zlibstatic freetype glm)
188190

189191
include(CTest)

demo/desktop/perlinWorld/sfml/sfmlPerlinWorld.cpp

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,16 @@ using namespace std::chrono;
4444
const int resX = 1000;
4545
const int resY = 1000;
4646
const float MAX_SPEED = 1.0/60.0;
47-
const unsigned MAX_THREADS = 8;
47+
const unsigned MAX_THREADS = 0;
4848

4949
// for smoothing delta numbers
5050
uint8_t frameId = 0;
5151
double deltas[60];
5252

5353
bool debug = false;
5454

55-
const double deltaPhysics = 1.0/900.0;
55+
const double deltaPhysics = 1.0/(900.0);
56+
const unsigned subSamples = 1;
5657

5758
using Hop::Object::Component::cTransform;
5859
using Hop::Object::Component::cPhysics;
@@ -176,7 +177,6 @@ int main(int argc, char ** argv)
176177
// setup physics system
177178
sPhysics & physics = manager.getSystem<sPhysics>();
178179
physics.setTimeStep(deltaPhysics);
179-
physics.setGravity(9.81);
180180

181181
sCollision & collisions = manager.getSystem<sCollision>();
182182

@@ -185,7 +185,7 @@ int main(int argc, char ** argv)
185185
auto res = std::make_unique<Hop::System::Physics::SpringDashpot>
186186
(
187187
deltaPhysics*10.0,
188-
0.66,
188+
0.5,
189189
0.0
190190
);
191191

@@ -201,15 +201,17 @@ int main(int argc, char ** argv)
201201

202202
console.luaStore(&luaStore);
203203

204-
console.runFile("test.lua");
204+
console.runFile("tests/circles.lua");
205205
std::string status = console.luaStatus();
206206
if (status != "LUA_OK") { WARN(status) >> log; }
207207

208208

209-
physics.stabaliseObjectParameters(&manager);
209+
//physics.stabaliseObjectParameters(&manager);
210210

211211
bool refreshObjectShaders = true;
212212

213+
bool paused = true;
214+
213215
while (window.isOpen())
214216
{
215217

@@ -239,40 +241,40 @@ int main(int argc, char ** argv)
239241
workers.joinThread();
240242
INFO("Thread: "+std::to_string(workers.size())) >> log;
241243
}
242-
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Space)
243-
{
244-
posX = 0.0; posY = 0.0;
245-
}
246244

247245
if (event.type == sf::Event::MouseWheelScrolled)
248246
{
249247
double z = event.mouseWheelScroll.delta;
250248
camera.incrementZoom(z);
251249
}
250+
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Space)
251+
{
252+
paused = !paused;
253+
}
252254
}
253255

254256
if ( sf::Keyboard::isKeyPressed(sf::Keyboard::W))
255257
{
256258

257-
posY += MAX_SPEED;
259+
posY += MAX_SPEED/camera.getZoomLevel();
258260

259261
}
260262
if (sf::Keyboard::isKeyPressed(sf::Keyboard::S))
261263
{
262264

263-
posY -= MAX_SPEED;
265+
posY -= MAX_SPEED/camera.getZoomLevel();
264266

265267
}
266268
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
267269
{
268270

269-
posX -= MAX_SPEED;
271+
posX -= MAX_SPEED/camera.getZoomLevel();
270272

271273
}
272274
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
273275
{
274276

275-
posX += MAX_SPEED;
277+
posX += MAX_SPEED/camera.getZoomLevel();
276278

277279
}
278280

@@ -287,17 +289,25 @@ int main(int argc, char ** argv)
287289

288290
collisions.centreOn(world.get()->getMapCenter());
289291

290-
if (workers.size() > 1)
292+
if (!paused)
291293
{
292-
collisions.update(&manager, world.get(),&workers);
293-
}
294-
else
295-
{
296-
collisions.update(&manager, world.get());
294+
for (unsigned k = 0 ; k < subSamples; k++)
295+
{
296+
if (workers.size() > 1)
297+
{
298+
collisions.update(&manager, world.get(),&workers);
299+
}
300+
else
301+
{
302+
collisions.update(&manager, world.get());
303+
}
304+
305+
physics.gravityForce(&manager,9.81,0.0,-1.0);
306+
307+
physics.update(&manager);
308+
}
297309
}
298310

299-
physics.update(&manager);
300-
301311
tp1 = high_resolution_clock::now();
302312

303313
tr0 = high_resolution_clock::now();
@@ -309,7 +319,24 @@ int main(int argc, char ** argv)
309319
rendering.update(&manager, &shaderPool, refreshObjectShaders);
310320
refreshObjectShaders = false;
311321

312-
rendering.draw(&shaderPool);
322+
rendering.draw(&shaderPool);
323+
324+
auto objects = manager.getObjects();
325+
326+
auto citer = objects.cbegin();
327+
auto cend = objects.cend();
328+
329+
while (citer != cend)
330+
{
331+
if (manager.hasComponent<cCollideable>(citer->first))
332+
{
333+
334+
cCollideable & c = manager.getComponent<cCollideable>(citer->first);
335+
336+
c.mesh.drawDebug(camera.getVP());
337+
}
338+
citer++;
339+
}
313340

314341
tr1 = high_resolution_clock::now();
315342

demo/desktop/perlinWorld/standalone/perlinWorld.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ int main(int argc, char ** argv)
174174

175175
console.luaStore(&luaStore);
176176

177-
console.runFile("test.lua");
177+
console.runFile("tests/circles.lua");
178178
std::string status = console.luaStatus();
179179
if (status != "LUA_OK") { WARN(status) >> log; }
180180

@@ -200,6 +200,8 @@ int main(int argc, char ** argv)
200200

201201
collisions.update(&manager, world.get());
202202

203+
physics.gravityForce(&manager,9.81,0.0,-1.0);
204+
203205
physics.update(&manager);
204206

205207
tp1 = high_resolution_clock::now();

0 commit comments

Comments
 (0)