Skip to content

Commit

Permalink
clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
malytomas committed Jun 8, 2023
1 parent e9dfbb5 commit f662bc1
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 208 deletions.
1 change: 1 addition & 0 deletions .editorconfig
2 changes: 1 addition & 1 deletion externals/cage
Submodule cage updated 334 files
1 change: 1 addition & 0 deletions sources/.clang-format
67 changes: 34 additions & 33 deletions sources/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include <cage-core/hashString.h>
#include <cage-core/variableSmoothingBuffer.h>
#include <cage-simple/fpsCamera.h>
#include <cage-engine/window.h>
#include <cage-engine/sceneScreenSpaceEffects.h>
#include <cage-engine/window.h>
#include <cage-simple/fpsCamera.h>

namespace
{
Expand Down Expand Up @@ -82,37 +82,38 @@ namespace
}
}

const auto engineInitListener = controlThread().initialize.listen([]() {
camera = engineEntities()->createUnique();
{
camera->value<TransformComponent>().position = Vec3(0, 0, 200);
CameraComponent &c = camera->value<CameraComponent>();
c.near = 1;
c.far = 500;
c.ambientColor = Vec3(1);
c.ambientIntensity = 0.1;
LightComponent &l = camera->value<LightComponent>();
l.lightType = LightTypeEnum::Directional;
l.color = Vec3(1);
l.intensity = 3;
l.ssaoFactor = 1;
camera->value<ScreenSpaceEffectsComponent>().effects = ScreenSpaceEffectsFlags::Default & ~ScreenSpaceEffectsFlags::AmbientOcclusion;
camera->value<ListenerComponent>();
}
const auto engineInitListener = controlThread().initialize.listen(
[]()
{
Entity *skybox = engineEntities()->createUnique();
skybox->value<TransformComponent>();
skybox->value<RenderComponent>().object = HashString("ants/skybox/skybox.object");
}
manualCamera = newFpsCamera(camera);
manualCamera->freeMove = true;
manualCamera->mouseButton = MouseButtonsFlags::Left;
manualCamera->movementSpeed = 3;
keyPressListener.attach(engineWindow()->events);
keyPressListener.bind(inputListener<InputClassEnum::KeyPress, InputKey>(&keyPress));
}, -200);
camera = engineEntities()->createUnique();
{
camera->value<TransformComponent>().position = Vec3(0, 0, 200);
CameraComponent &c = camera->value<CameraComponent>();
c.near = 1;
c.far = 500;
c.ambientColor = Vec3(1);
c.ambientIntensity = 0.1;
LightComponent &l = camera->value<LightComponent>();
l.lightType = LightTypeEnum::Directional;
l.color = Vec3(1);
l.intensity = 3;
l.ssaoFactor = 1;
camera->value<ScreenSpaceEffectsComponent>().effects = ScreenSpaceEffectsFlags::Default & ~ScreenSpaceEffectsFlags::AmbientOcclusion;
camera->value<ListenerComponent>();
}
{
Entity *skybox = engineEntities()->createUnique();
skybox->value<TransformComponent>();
skybox->value<RenderComponent>().object = HashString("ants/skybox/skybox.object");
}
manualCamera = newFpsCamera(camera);
manualCamera->freeMove = true;
manualCamera->mouseButton = MouseButtonsFlags::Left;
manualCamera->movementSpeed = 3;
keyPressListener.attach(engineWindow()->events);
keyPressListener.bind(inputListener<InputClassEnum::KeyPress, InputKey>(&keyPress));
},
-200);

const auto engineUpdateListener = controlThread().update.listen([]() {
autoCamera.update();
}, 200);
const auto engineUpdateListener = controlThread().update.listen([]() { autoCamera.update(); }, 200);
}
2 changes: 1 addition & 1 deletion sources/common.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef ants_common_h_sdg456ds4hg6
#define ants_common_h_sdg456ds4hg6

#include <cage-core/math.h>
#include <cage-core/entities.h>
#include <cage-core/math.h>
#include <cage-core/profiling.h>
#include <cage-engine/scene.h>
#include <cage-simple/engine.h>
Expand Down
19 changes: 11 additions & 8 deletions sources/components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

namespace
{
const auto engineInitListener = controlThread().initialize.listen([]() {
engineEntities()->defineComponent(PhysicsComponent());
engineEntities()->defineComponent(OwnerComponent());
engineEntities()->defineComponent(LifeComponent());
engineEntities()->defineComponent(ShipComponent());
engineEntities()->defineComponent(PlanetComponent());
engineEntities()->defineComponent(TimeoutComponent());
}, -100);
const auto engineInitListener = controlThread().initialize.listen(
[]()
{
engineEntities()->defineComponent(PhysicsComponent());
engineEntities()->defineComponent(OwnerComponent());
engineEntities()->defineComponent(LifeComponent());
engineEntities()->defineComponent(ShipComponent());
engineEntities()->defineComponent(PlanetComponent());
engineEntities()->defineComponent(TimeoutComponent());
},
-100);
}
48 changes: 25 additions & 23 deletions sources/gui.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "common.h"

#include <cage-core/string.h>
#include <cage-engine/guiManager.h>
#include <cage-engine/guiBuilder.h>
#include <cage-engine/guiManager.h>

#include <initializer_list>

Expand Down Expand Up @@ -42,30 +42,32 @@ namespace
}
}

const auto engineInitListener = controlThread().initialize.listen([]() {
Holder<GuiBuilder> g = newGuiBuilder(engineGuiEntities());
const auto engineInitListener = controlThread().initialize.listen(
[]()
{
Holder<GuiBuilder> g = newGuiBuilder(engineGuiEntities());

guiListener.attach(engineGuiManager()->widgetEvent);
guiListener.bind(inputListener<InputClassEnum::GuiWidget, InputGuiWidget>(&guiEvent));
guiListener.attach(engineGuiManager()->widgetEvent);
guiListener.bind(inputListener<InputClassEnum::GuiWidget, InputGuiWidget>(&guiEvent));

auto _1 = g->alignment(Vec2());
auto _2 = g->spoiler().text("Ships");
auto _3 = g->verticalTable(2);
auto _1 = g->alignment(Vec2());
auto _2 = g->spoiler().text("Ships");
auto _3 = g->verticalTable(2);

static_assert(sizeof(propertyNames) / sizeof(propertyNames[0]) == sizeof(propertyValues) / sizeof(propertyValues[0]), "arrays must have same length");
for (uint32 i = 0; i < sizeof(propertyNames) / sizeof(propertyNames[0]); i++)
{
g->label().text(propertyNames[i]);
g->setNextName(20 + i).input(*propertyValues[i], 0, 0.05, 0.0002);
}
static_assert(sizeof(propertyNames) / sizeof(propertyNames[0]) == sizeof(propertyValues) / sizeof(propertyValues[0]), "arrays must have same length");
for (uint32 i = 0; i < sizeof(propertyNames) / sizeof(propertyNames[0]); i++)
{
g->label().text(propertyNames[i]);
g->setNextName(20 + i).input(*propertyValues[i], 0, 0.05, 0.0002);
}

for (uint32 i : { 5, 6 })
{
// radiuses
GuiInputComponent &c = engineGuiEntities()->get(20 + i)->value<GuiInputComponent>();
c.min.f = 0.1;
c.max.f = 10.0;
c.step.f = 0.1;
}
});
for (uint32 i : { 5, 6 })
{
// radiuses
GuiInputComponent &c = engineGuiEntities()->get(20 + i)->value<GuiInputComponent>();
c.min.f = 0.1;
c.max.f = 10.0;
c.step.f = 0.1;
}
});
}
12 changes: 6 additions & 6 deletions sources/main.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include <cage-core/logger.h>
#include <cage-core/math.h>
#include <cage-core/config.h>
#include <cage-core/assetManager.h>
#include <cage-core/ini.h>
#include <cage-core/config.h>
#include <cage-core/hashString.h>
#include <cage-core/ini.h>
#include <cage-core/logger.h>
#include <cage-core/math.h>

#include <cage-engine/window.h>
#include <cage-engine/highPerformanceGpuHint.h>
#include <cage-engine/window.h>
#include <cage-simple/engine.h>
#include <cage-simple/statisticsGui.h>
#include <cage-simple/fullscreenSwitcher.h>
#include <cage-simple/statisticsGui.h>

using namespace cage;

Expand Down
33 changes: 18 additions & 15 deletions sources/physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@

namespace
{
const auto engineUpdateListener = controlThread().update.listen([]() {
ProfilingScope profiling("physics");
for (Entity *e : engineEntities()->component<PhysicsComponent>()->entities())
const auto engineUpdateListener = controlThread().update.listen(
[]()
{
TransformComponent &t = e->value<TransformComponent>();
PhysicsComponent &p = e->value<PhysicsComponent>();
CAGE_ASSERT(p.acceleration.valid() && p.velocity.valid() && t.position.valid());
CAGE_ASSERT(p.rotation.valid() && t.orientation.valid());
p.velocity += p.acceleration;
if (lengthSquared(p.velocity) > sqr(p.maxSpeed))
p.velocity = normalize(p.velocity) * p.maxSpeed;
p.acceleration = Vec3();
t.position += p.velocity;
t.orientation = p.rotation * t.orientation;
}
}, 100);
ProfilingScope profiling("physics");
for (Entity *e : engineEntities()->component<PhysicsComponent>()->entities())
{
TransformComponent &t = e->value<TransformComponent>();
PhysicsComponent &p = e->value<PhysicsComponent>();
CAGE_ASSERT(p.acceleration.valid() && p.velocity.valid() && t.position.valid());
CAGE_ASSERT(p.rotation.valid() && t.orientation.valid());
p.velocity += p.acceleration;
if (lengthSquared(p.velocity) > sqr(p.maxSpeed))
p.velocity = normalize(p.velocity) * p.maxSpeed;
p.acceleration = Vec3();
t.position += p.velocity;
t.orientation = p.rotation * t.orientation;
}
},
100);
}
100 changes: 53 additions & 47 deletions sources/planets.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "common.h"

#include <cage-core/hashString.h>
#include <cage-core/color.h>
#include <cage-core/hashString.h>

#include <vector>

Expand All @@ -26,34 +26,37 @@ namespace
constexpr uint32 batchScale = 10;
#endif // CAGE_DEBUG

const auto engineInitListener = controlThread().initialize.listen([]() {
uint32 playersCount = randomRange(2u, 5u);
std::vector<Vec3> playerColors;
playerColors.resize(playersCount);
Real hueOff = randomChance();
for (uint32 p = 0; p < playersCount; p++)
playerColors[p] = colorHsvToRgb(Vec3((Real(p) / playersCount + hueOff) % 1, randomRange(0.5, 1.0), randomRange(0.5, 1.0)));
uint32 planetsCount = randomRange(3u, 12u);
for (uint32 p = 0; p < planetsCount; p++)
const auto engineInitListener = controlThread().initialize.listen(
[]()
{
Entity *e = engineEntities()->createUnique();
TransformComponent &t = e->value<TransformComponent>();
t.position = randomDirection3() * randomRange(80, 150);
t.orientation = randomDirectionQuat();
t.scale = 5;
OwnerComponent &owner = e->value<OwnerComponent>();
owner.owner = p % playersCount;
RenderComponent &r = e->value<RenderComponent>();
r.object = modelNames[randomRange(0u, (uint32)(sizeof(modelNames) / sizeof(modelNames[0])))];
r.color = playerColors[owner.owner];
PhysicsComponent &physics = e->value<PhysicsComponent>();
physics.rotation = interpolate(Quat(), randomDirectionQuat(), 0.0003);
LifeComponent &life = e->value<LifeComponent>();
life.life = randomRange(1000000, 2000000);
PlanetComponent &planet = e->value<PlanetComponent>();
planet.batch = randomRange(3 * batchScale, 5 * batchScale);
}
}, -50);
uint32 playersCount = randomRange(2u, 5u);
std::vector<Vec3> playerColors;
playerColors.resize(playersCount);
Real hueOff = randomChance();
for (uint32 p = 0; p < playersCount; p++)
playerColors[p] = colorHsvToRgb(Vec3((Real(p) / playersCount + hueOff) % 1, randomRange(0.5, 1.0), randomRange(0.5, 1.0)));
uint32 planetsCount = randomRange(3u, 12u);
for (uint32 p = 0; p < planetsCount; p++)
{
Entity *e = engineEntities()->createUnique();
TransformComponent &t = e->value<TransformComponent>();
t.position = randomDirection3() * randomRange(80, 150);
t.orientation = randomDirectionQuat();
t.scale = 5;
OwnerComponent &owner = e->value<OwnerComponent>();
owner.owner = p % playersCount;
RenderComponent &r = e->value<RenderComponent>();
r.object = modelNames[randomRange(0u, (uint32)(sizeof(modelNames) / sizeof(modelNames[0])))];
r.color = playerColors[owner.owner];
PhysicsComponent &physics = e->value<PhysicsComponent>();
physics.rotation = interpolate(Quat(), randomDirectionQuat(), 0.0003);
LifeComponent &life = e->value<LifeComponent>();
life.life = randomRange(1000000, 2000000);
PlanetComponent &planet = e->value<PlanetComponent>();
planet.batch = randomRange(3 * batchScale, 5 * batchScale);
}
},
-50);

void createShip(Entity *planet, uint32 target)
{
Expand All @@ -79,24 +82,27 @@ namespace

uint32 planetIndex = 0;

const auto engineUpdateListener = controlThread().update.listen([]() {
ProfilingScope profiling("planets");
uint32 shipsCount = engineEntities()->component<ShipComponent>()->count();
uint32 planetsCount = engineEntities()->component<PlanetComponent>()->count();
uint32 currentIndex = 0;
for (Entity *e : engineEntities()->component<PlanetComponent>()->entities())
const auto engineUpdateListener = controlThread().update.listen(
[]()
{
PlanetComponent &p = e->value<PlanetComponent>();
if (currentIndex++ != (planetIndex % planetsCount))
continue;
if (shipsCount + p.batch > shipsLimit)
continue;
OwnerComponent &owner = e->value<OwnerComponent>();
uint32 target = pickTargetPlanet(owner.owner);
for (uint32 s = 0; s < p.batch; s++)
createShip(e, target);
p.batch = randomRange(3 * batchScale, 5 * batchScale);
planetIndex++;
}
}, 60);
ProfilingScope profiling("planets");
uint32 shipsCount = engineEntities()->component<ShipComponent>()->count();
uint32 planetsCount = engineEntities()->component<PlanetComponent>()->count();
uint32 currentIndex = 0;
for (Entity *e : engineEntities()->component<PlanetComponent>()->entities())
{
PlanetComponent &p = e->value<PlanetComponent>();
if (currentIndex++ != (planetIndex % planetsCount))
continue;
if (shipsCount + p.batch > shipsLimit)
continue;
OwnerComponent &owner = e->value<OwnerComponent>();
uint32 target = pickTargetPlanet(owner.owner);
for (uint32 s = 0; s < p.batch; s++)
createShip(e, target);
p.batch = randomRange(3 * batchScale, 5 * batchScale);
planetIndex++;
}
},
60);
}
Loading

0 comments on commit f662bc1

Please sign in to comment.