Skip to content

Commit

Permalink
Added docs and fixed typos
Browse files Browse the repository at this point in the history
  • Loading branch information
hudrima1 committed Jul 5, 2024
1 parent 9f26fb3 commit ae5dc84
Show file tree
Hide file tree
Showing 18 changed files with 189 additions and 64 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![Build & Deploy Docs](https://github.com/cpvrlab/SLProject4/actions/workflows/deploy-pages.yml/badge.svg)](https://github.com/cpvrlab/SLProject4/actions/workflows/deploy-pages.yml)


SL stands for Scene Library. It is developed at the Berne University of Applied Sciences (BFH) in Switzerland and is used for student projects in the cpvrLab. The various applications show what you can learn in three semesters about 3D computer graphics in real-time rendering and ray tracing. The framework is built in C++ and OpenGL ES and can be built for Windows, Linux, macOS (Intel & arm64), Android, Apple iOS, and WebAssembly-enabled browsers. The framework can render alternatively with Ray Tracing and Path Tracing, which provides high-quality transparencies, reflections, and soft shadows. For a complete feature list see the [SLProject4 wiki](https://github.com/cpvrlab/SLProject4/wiki).
SL stands for Scene Library. It is developed at the Bern University of Applied Sciences (BFH) in Switzerland and is used for student projects in the cpvrLab. The various applications show what you can learn in three semesters about 3D computer graphics in real-time rendering and ray tracing. The framework is built in C++ and OpenGL ES and can be built for Windows, Linux, macOS (Intel & arm64), Android, Apple iOS, and WebAssembly-enabled browsers. The framework can render alternatively with Ray Tracing and Path Tracing, which provides high-quality transparencies, reflections, and soft shadows. For a complete feature list see the [SLProject4 wiki](https://github.com/cpvrlab/SLProject4/wiki).

## How to get the SLProject4

Expand Down
1 change: 1 addition & 0 deletions apps/source/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ typedef void (*OnGuiBuildCallback)(SLScene* s, SLSceneView* sv);
typedef void (*OnGuiLoadConfigCallback)(SLint dotsPerInch);
typedef void (*OnGuiSaveConfigCallback)();

//! App configuration struct to be passed to the App::run function
struct Config
{
int argc = 0;
Expand Down
2 changes: 1 addition & 1 deletion apps/source/CVCapture.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* \file CVCapture
* \brief OpenCV Capture Device
* \brief OpenCV Capture Device
* \date Winter 2016
* \remarks Please use clangformat to format the code. See more code style on
* https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
Expand Down
30 changes: 28 additions & 2 deletions apps/source/sm/Event.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
/**
* \file Event.h
* \brief Event class used in the state machine
* \authors Michael Göttlicher
* \copyright http://opensource.org/licenses/GPL-3.0
* \remarks Please use clangformat to format the code. See more code style on
* https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
*/

#ifndef SM_EVENT_H
#define SM_EVENT_H

#include <map>
#include <string>
#include <sm/EventData.h>

/**
* @brief Collection of classes for a state machine implementation used in the Erleb-AR app.
* @author Micheal Göttlicher
* \copyright http://opensource.org/licenses/GPL-3.0
* \remarks Please use clangformat to format the code. See more code style on
* https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
*/
namespace sm
{

//-----------------------------------------------------------------------------
/**
* @brief Event class used in the state machine
*/
class Event
{
public:
Expand All @@ -30,7 +50,7 @@ class Event
_transitions[from] = to;
}

// Check if there is a transition to a new state. The current state is used to lookup the new state.
//! Check if there is a transition to a new state. The current state is used to lookup the new state.
unsigned int getNewState(unsigned int currentState)
{
auto it = _transitions.find(currentState);
Expand All @@ -43,7 +63,12 @@ class Event
return EVENT_IGNORED;
}
}
// get event data that was possibly send with this event. If the function returns nullptr, it contains no data.
/**
* @brief Get event data that was possibly send with this event.
* If the function returns nullptr, it contains no data.
*
* @return EventData*
*/
EventData* getEventData()
{
return _eventData;
Expand All @@ -61,6 +86,7 @@ class Event
std::string _name;
std::string _senderInfo;
};
//-----------------------------------------------------------------------------
}

#endif
13 changes: 11 additions & 2 deletions apps/source/sm/EventData.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
/**
* \file EventData.h
* \brief Event class used in the state machine
* \authors Michael Göttlicher
* \copyright http://opensource.org/licenses/GPL-3.0
* \remarks Please use clangformat to format the code. See more code style on
* https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
*/
#ifndef SM_EVENT_DATA_H
#define SM_EVENT_DATA_H

namespace sm
{

//-----------------------------------------------------------------------------
class EventData
{
public:
virtual ~EventData() {}
};

//-----------------------------------------------------------------------------
class NoEventData : public EventData
{
public:
NoEventData()
{
}
};

//-----------------------------------------------------------------------------
}
#endif
55 changes: 44 additions & 11 deletions apps/source/sm/StateMachine.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* \file StateMachinge.cpp
* \brief State Machine Class Implementation
* \authors Michael Göttlicher
* \copyright http://opensource.org/licenses/GPL-3.0
* \remarks Please use clangformat to format the code. See more code style on
* https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
*/

#include "StateMachine.h"
#include <sstream>

Expand All @@ -7,19 +16,20 @@

namespace sm
{
//-----------------------------------------------------------------------------
StateMachine::StateMachine(unsigned int initialStateId)
: _currentStateId(initialStateId)
{
}

//-----------------------------------------------------------------------------
StateMachine::~StateMachine()
{
for (auto it : _stateActions)
{
delete it.second;
}
};

//-----------------------------------------------------------------------------
bool StateMachine::update()
{
sm::EventData* data = nullptr;
Expand All @@ -34,26 +44,38 @@ bool StateMachine::update()
unsigned int newState = e->getNewState(_currentStateId);
data = e->getEventData();

LOG_STATEMACHINE_DEBUG("Event %s received sent by %s", e->name(), e->senderInfo());
LOG_STATEMACHINE_DEBUG("Event %s received sent by %s",
e->name(),
e->senderInfo());

if (newState != Event::EVENT_IGNORED)
{
if (_currentStateId != newState)
{
stateEntry = true;
LOG_STATEMACHINE_DEBUG("State change: %s -> %s", getPrintableState(_currentStateId).c_str(), getPrintableState(newState).c_str());
LOG_STATEMACHINE_DEBUG("State change: %s -> %s",
getPrintableState(_currentStateId).c_str(),
getPrintableState(newState).c_str());

// inform old state that we will leave it soon
auto itStateAction = _stateActions.find(_currentStateId);
if (itStateAction != _stateActions.end())
{
itStateAction->second->invokeStateAction(this, data, false, true);
itStateAction->second->invokeStateAction(this,
data,
false,
true);
}
else
{
std::stringstream ss;
ss << "You forgot to register state " << getPrintableState(_currentStateId) << "!";
Utils::exitMsg("StateMachine", ss.str().c_str(), __LINE__, __FILE__);
ss << "You forgot to register state "
<< getPrintableState(_currentStateId)
<< "!";
Utils::exitMsg("StateMachine",
ss.str().c_str(),
__LINE__,
__FILE__);
}

// update state
Expand All @@ -62,19 +84,29 @@ bool StateMachine::update()
auto itStateAction = _stateActions.find(_currentStateId);
if (itStateAction != _stateActions.end())
{
itStateAction->second->invokeStateAction(this, data, stateEntry, false);
itStateAction->second->invokeStateAction(this,
data,
stateEntry,
false);
}
else
{
std::stringstream ss;
ss << "You forgot to register state " << getPrintableState(_currentStateId) << "!";
Utils::exitMsg("StateMachine", ss.str().c_str(), __LINE__, __FILE__);
ss << "You forgot to register state "
<< getPrintableState(_currentStateId)
<< "!";
Utils::exitMsg("StateMachine",
ss.str().c_str(),
__LINE__,
__FILE__);
}
stateWasUpdated = true;
}
else
{
LOG_STATEMACHINE_DEBUG("Event %s ignored in state %s", e->name(), getPrintableState(_currentStateId).c_str());
LOG_STATEMACHINE_DEBUG("Event %s ignored in state %s",
e->name(),
getPrintableState(_currentStateId).c_str());
}

delete e;
Expand All @@ -88,4 +120,5 @@ bool StateMachine::update()

return true;
}
//-----------------------------------------------------------------------------
}
41 changes: 32 additions & 9 deletions apps/source/sm/StateMachine.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* \file StateMachinge.h
* \brief State Machine Class Declaration
* \authors Michael Göttlicher
* \copyright http://opensource.org/licenses/GPL-3.0
* \remarks Please use clangformat to format the code. See more code style on
* https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
*/

#ifndef SM_STATE_MACHINE_H
#define SM_STATE_MACHINE_H

Expand All @@ -8,9 +17,9 @@

namespace sm
{

//-----------------------------------------------------------------------------
class StateMachine;

//-----------------------------------------------------------------------------
/// @brief Abstract state base class that all states inherit from.
class StateBase
{
Expand All @@ -24,9 +33,12 @@ class StateBase
* \param stateEntry
* \param stateExit
*/
virtual void invokeStateAction(StateMachine* sm, const EventData* data, const bool stateEntry, const bool stateExit) const {};
virtual void invokeStateAction(StateMachine* sm,
const EventData* data,
const bool stateEntry,
const bool stateExit) const {};
};

//-----------------------------------------------------------------------------
/*!
* StateAction takes three template arguments: A state machine class,
* a state function event data type (derived from EventData) and a state machine
Expand All @@ -35,11 +47,18 @@ class StateBase
* \tparam Data
* \tparam Func
*/
template<class SM, class Data, void (SM::*Func)(const Data*, const bool, const bool)>
template<class SM,
class Data,
void (SM::*Func)(const Data*,
const bool,
const bool)>
class StateAction : public StateBase
{
public:
virtual void invokeStateAction(StateMachine* sm, const EventData* data, const bool stateEntry, const bool stateExit) const
virtual void invokeStateAction(StateMachine* sm,
const EventData* data,
const bool stateEntry,
const bool stateExit) const
{
// Downcast the state machine and event data to the correct derived type
SM* derivedSM = static_cast<SM*>(sm);
Expand All @@ -50,7 +69,7 @@ class StateAction : public StateBase
(derivedSM->*Func)(derivedData, stateEntry, stateExit);
}
};

//-----------------------------------------------------------------------------
/*!
- Transfer id of initial state in constructor of StateMachine
- Define state functions like: void <name>(const sm::EventData* data);
Expand All @@ -69,7 +88,11 @@ class StateMachine : public EventHandler

protected:
//! register state processing functions from deriving class
template<class SM, class Data, void (SM::*Func)(const Data*, const bool, const bool)>
template<class SM,
class Data,
void (SM::*Func)(const Data*,
const bool,
const bool)>
void registerState(unsigned int stateId)
{
assert(_stateActions.find(stateId) == _stateActions.end());
Expand All @@ -81,7 +104,7 @@ class StateMachine : public EventHandler

std::map<unsigned int, sm::StateBase*> _stateActions;
};

//-----------------------------------------------------------------------------
} // namespace SM

#endif
Loading

0 comments on commit ae5dc84

Please sign in to comment.