Skip to content

Commit

Permalink
Merge pull request #44 from brenocq/0.3.0.0
Browse files Browse the repository at this point in the history
Linux compilation
  • Loading branch information
brenocq authored Nov 20, 2022
2 parents 4c2b752 + 4429792 commit d67f4d9
Show file tree
Hide file tree
Showing 20 changed files with 272 additions and 178 deletions.
24 changes: 10 additions & 14 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,28 @@ jobs:
matrix:
config:
- {
name: "Ubuntu Latest",
name: "Ubuntu g++",
os: ubuntu-latest,
build_type: "Release"
compiler: "g++"
}
- {
name: "Ubuntu clang++",
os: ubuntu-latest,
compiler: "clang++"
}

steps:
- name: Checkout atta
uses: actions/checkout@v2

- name: Install dependencies on ubuntu
if: startsWith(matrix.config.os, 'ubuntu')
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install cmake xorg-dev curl
cmake --version
gcc --version
- name: Configure
run: |
mkdir build
cd build
cmake ..
- name: Build
run: cmake --build build --parallel --config ${{ matrix.config.build_type }}
run: ./build.sh --jobs 2 --compiler ${{ matrix.config.compiler }}

- name: Test
run: ctest
working-directory: build
working-directory: build/release
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.14)

project(atta VERSION 0.2.0.0 LANGUAGES CXX C)
project(atta VERSION 0.3.0.0 LANGUAGES CXX C)

OPTION(ATTA_BUILD_TESTS
"Set to ON to build also the test executables"
Expand All @@ -22,8 +22,8 @@ set(ATTA_VERSION_SAFE atta-${CMAKE_PROJECT_VERSION})

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/atta/cmakeConfig.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/atta/cmakeConfig.h)

# Set flags necessary for the script system to work correctly
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# Set flags necessary for the script system to work correctly
set(CMAKE_CXX_FLAGS "-Wl,--export-dynamic")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--export-dynamic")
endif()
Expand Down
80 changes: 55 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,40 +77,70 @@ Arrows show dependencies between modules. Green boxes show which features are im
This project aims to simulate complex systems like this, mainly composed of robots.

## Build & test
#### Dependencies
To build atta properly, you need to have cmake installed.
Dependencies for some operating systems:

**Windows:**
```bash
choco install cmake
```

**MacOS:**
```bash
brew install cmake
```

**Linux:**
```bash
sudo apt-get install cmake xorg-dev curl
```

#### Clone
Atta should build without errors when the **compiller supports C++17** (g++ >= 9.0).
<!------------ Windows ------------>
<details><summary> Windows </summary>
<h4>Dependencies</h4>
To build atta properly, you need to have cmake installed.
<pre><code>choco install cmake</code></pre>
Also, be sure that your <strong>compiller supports C++17</strong> (g++ >= 9.0).

If you found any errors, please do not hesitate to [create an issue](https://github.com/brenocq/atta/issues/new?assignees=brenocq&labels=fix&template=bug_report.md&title=) :wink:.
<h4>Run</h4>
<pre><code>git clone [email protected]:brenocq/atta.git
cd atta
mkdir build
cd build
cmake ..
</code></pre>

You can now use Visual Studio to open the <code>atta.sln</code> file.
</details>
<!------------ MacOS ------------>
<details><summary> MacOS </summary>
<h4>Dependencies</h4>
To build atta properly, you need to have cmake installed.
<pre><code>brew install cmake</code></pre>
Also, be sure that your <strong>compiller supports C++17</strong> (g++ >= 9.0).

```bash
git clone [email protected]:brenocq/atta.git
<h4>Run</h4>
<pre><code>git clone [email protected]:brenocq/atta.git
cd atta
./scripts/build.sh --help
./scripts/build.sh
./build/release/bin/atta_test
./build/release/bin/atta
```
</code></pre>
</details>
<!------------ Linux ------------>
<details><summary> Linux </summary>
<h3>Dependencies</h3>
To build atta, you need:
<ul>
<li>g++ >= 9.0</li>
<li>cmake >= 3.14</li>
</ul>

<strong>Ubuntu:</strong>
<pre><code>sudo apt-get install g++ cmake git xorg-dev curl</code></pre>
<i>Note: If your ubuntu is old, you may need to install the latest cmake/g++ manually.</i>

<strong>Fedora:</strong>
<pre><code>sudo yum install g++ cmake git glfw-devel curl</code></pre>

<strong>Arch:</strong>
<pre><code>sudo pacman -Sy g++ cmake git glfw-x11 curl</code></pre>

<h3>Run</h3>
<pre><code>git clone [email protected]:brenocq/atta.git
cd atta
./build.sh --help
./build.sh
./build/release/bin/atta_test
./build/release/bin/atta
</code></pre>
</details>

_Obs: The build script should help the user with dependencies. If you found ploblems please let me know_
If you found any errors, please do not hesitate to [create an issue](https://github.com/brenocq/atta/issues/new?assignees=brenocq&labels=fix&template=bug_report.md&title=) :wink:.

## Discussions
If you want to contribute, have ideas, or have questions about atta, feel free to [start a discussion](https://github.com/brenocq/atta/discussions).
Expand Down
21 changes: 15 additions & 6 deletions scripts/build.sh → build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e

SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
SOURCE_PATH="$SCRIPT_PATH/.."
SOURCE_PATH="$SCRIPT_PATH"
BUILD_PATH="$SOURCE_PATH/build"
CMAKE_BUILD_TYPE="-DCMAKE_BUILD_TYPE=Release"
CMAKE_COMPILER=""
Expand All @@ -14,14 +14,15 @@ BUILD_TYPE="default"
RUN_AFTER="false"
PROJECT_TO_RUN=""
INSTALL_AFTER="false"
NUM_JOBS=""

printHelp()
{
echo "Atta build script"
echo
echo "Usage: ./build.sh [args ...]"
echo "Usage: ./build.sh [option(s)]"
echo
echo "options:"
echo "Options:"
echo
echo "-h or --help"
echo " This help menu"
Expand All @@ -39,6 +40,9 @@ printHelp()
echo "-c or --compiler <name>"
echo " Select the compiler."
echo
echo "-j or --jobs <num_jobs>"
echo " Set number of jobs to use when building."
echo
echo "-s or --static <project_file>"
echo " Build statically linked to a project."
echo " The file should be a valid .atta"
Expand All @@ -59,7 +63,7 @@ buildDefault()
echo "---------- Building ----------"
# Build
cmake $CMAKE_BUILD_TYPE $CMAKE_COMPILER $CMAKE_ATTA_STATIC $SOURCE_PATH
make -j
make -j $NUM_JOBS

# Install
if [[ "$INSTALL_AFTER" == "true" ]]; then
Expand Down Expand Up @@ -97,7 +101,7 @@ buildWeb()
# Build
echo "---------- Building web ----------"
emcmake cmake $CMAKE_MODULE $CMAKE_BUILD_TYPE $CMAKE_ATTA_STATIC $SOURCE_PATH
make -j
make -j $NUM_JOBS

# Run
if [[ "$RUN_AFTER" == "true" ]]; then
Expand All @@ -112,7 +116,7 @@ buildDocs()
{
echo "---------- Building docs ----------"
cmake -ATTA_BUILD_DOCS=ON -DATTA_BUILD_TESTS=OFF $SOURCE_PATH
make -j
make -j $NUM_JOBS
exit
}

Expand All @@ -136,6 +140,11 @@ while [[ $# -gt 0 ]]; do
RUN_AFTER="true"
shift # past argument
;;
-j|--jobs)
NUM_JOBS="$2"
shift # past argument
shift # past value
;;
-p|--project)
PROJECT_TO_RUN="$2"
shift # past argument
Expand Down
81 changes: 44 additions & 37 deletions src/atta/atta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ Atta::Atta(const CreateInfo& info) : _shouldFinish(false), _simulationState(Simu
LOG_WARN("Atta", "Project [w]$0[] will not be open because atta was built statically linked to [w]$1[]", info.projectFile, projectFile);
#else
// If a project was defined as argument, open project
if (!info.projectFile.empty())
{
graphics::update();// Need to update to register the viewports
if (!info.projectFile.empty()) {
graphics::update(); // Need to update to register the viewports
file::openProject(info.projectFile);
}
#endif
Expand Down Expand Up @@ -123,24 +122,32 @@ void Atta::loop() {
if (project)
project->onUpdateBefore(dt);

// Run entity scripts
// TODO keep list of entities that have script (and are not prototype entities)
// Run clone scripts
for (auto& factory : component::getFactories())
factory.runScripts(dt);

// Run scripts of other entities (not clones)
const auto& factories = component::getFactories();
std::vector<std::pair<component::EntityId, component::EntityId>> beginEndClones(factories.size());
for (const auto& factory : factories)
beginEndClones.push_back({factory.getFirstClone(), factory.getLastClone()});
std::vector<component::EntityId> entities = component::getScriptView();
for (component::EntityId entity : entities) {
// Check if it it not clone entity
for(auto [begin, end] : beginEndClones)
if(entity >= begin && entity <= end)
continue;

// Check if it is not prototype entity
component::Script* scriptComponent = component::getComponent<component::Script>(entity);
component::Prototype* prototypeComponent = component::getComponent<component::Prototype>(entity);
if (scriptComponent && !prototypeComponent) {
// std::vector<Component*> components = component::getComponents(entity);
script::Script* script = script::getScript(scriptComponent->sid);
if (script)
script->update(component::Entity(entity), dt);
}
}

// Run clone scripts
for (auto& factory : component::getFactories())
factory.runScripts(dt);

if (project)
project->onUpdateAfter(dt);
}
Expand Down Expand Up @@ -171,33 +178,33 @@ void Atta::onWindowClose(event::Event& event) { _shouldFinish = true; }
void Atta::onSimulationStateChange(event::Event& event) {
script::ProjectScript* project = script::getProjectScript();
switch (event.getType()) {
case event::SimulationStart::type: {
if (project)
project->onStart();
_simulationState = SimulationState::RUNNING;
break;
}
case event::SimulationContinue::type: {
if (project)
project->onContinue();
_simulationState = SimulationState::RUNNING;
break;
}
case event::SimulationPause::type: {
if (project)
project->onPause();
_simulationState = SimulationState::PAUSED;
break;
}
case event::SimulationStop::type: {
if (project)
project->onStop();
_simulationState = SimulationState::NOT_RUNNING;
break;
}
default: {
LOG_WARN("Atta", "Unknown simulation event");
}
case event::SimulationStart::type: {
if (project)
project->onStart();
_simulationState = SimulationState::RUNNING;
break;
}
case event::SimulationContinue::type: {
if (project)
project->onContinue();
_simulationState = SimulationState::RUNNING;
break;
}
case event::SimulationPause::type: {
if (project)
project->onPause();
_simulationState = SimulationState::PAUSED;
break;
}
case event::SimulationStop::type: {
if (project)
project->onStop();
_simulationState = SimulationState::NOT_RUNNING;
break;
}
default: {
LOG_WARN("Atta", "Unknown simulation event");
}
}
}
} // namespace atta
3 changes: 1 addition & 2 deletions src/atta/component/components/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ const std::vector<uint8_t>& Camera::getFrame() {
for (auto& cameraInfo : cameraInfos)
if (cameraInfo.component == this)
return cameraInfo.data;
LOG_ERROR("component::Camera", "Could not get camera frame from sensor::Manager");
return {};
ASSERT(false, "(component::Camera) Could not get camera frame from sensor::Manager");
}

} // namespace atta::component
22 changes: 0 additions & 22 deletions src/atta/component/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ void Factory::destroyClones() {
}

void Factory::runScripts(float dt) {
// TODO faster
unsigned cloneId = 0;
for (EntityId entity = _firstCloneEid; entity < EntityId(_firstCloneEid + _maxClones); entity++) {
Script* scriptComponent = component::getComponent<Script>(entity);
Expand All @@ -81,27 +80,6 @@ void Factory::runScripts(float dt) {
}
cloneId++;
}

// Example using componentMemories to set Entity component vector
// Script* scriptComponent = component::getComponent<script::Script>(_prototypeId);
// if(scriptComponent)
//{
// Script* script = script::getScript(scriptComponent->sid);
// if(script)
// {
// // Execute each clone script with the right component
// for(unsigned cloneId = 0; cloneId < _maxClones; cloneId++)
// {
// // Populate component memories
// for(unsigned i = 0; i < components.size(); i++)
// components[i] = reinterpret_cast<Component*>(_componentMemories[i].second +
// cloneId * _componentRegistries[i]->getSizeof());

// Run script
// script->update(_prototypeId, cloneId, components, dt);
// }
// }
//}
}

EntityId Factory::getPrototypeId() const { return _prototypeId; }
Expand Down
Loading

0 comments on commit d67f4d9

Please sign in to comment.