Rearrangements; Audio support
This commit is contained in:
5
src/characters/CMakeLists.txt
Normal file
5
src/characters/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
project(characters)
|
||||
find_package(OGRE REQUIRED COMPONENTS Bites Bullet Paging Terrain CONFIG)
|
||||
add_library(controller STATIC controller.cpp)
|
||||
target_link_libraries(controller PUBLIC OgreMain OgreBites PRIVATE GameData)
|
||||
target_include_directories(controller PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <OgreMath.h>
|
||||
#include "GameData.h"
|
||||
#include "character.h"
|
||||
#include "controller.h"
|
||||
#if 0
|
||||
@@ -227,14 +228,11 @@ void CharacterController::setupBody()
|
||||
}
|
||||
mGhostObject->setCollisionFlags(
|
||||
btCollisionObject::CF_KINEMATIC_OBJECT |
|
||||
btCollisionObject::CF_NO_CONTACT_RESPONSE );
|
||||
btCollisionObject::CF_NO_CONTACT_RESPONSE);
|
||||
mGhostObject->setActivationState(DISABLE_DEACTIVATION);
|
||||
mWorld->attachCollisionObject(mGhostObject, mBodyEnt,
|
||||
1,
|
||||
0x7FFFFFF);
|
||||
mController =
|
||||
new Ogre::Bullet::KinematicMotionSimple(mGhostObject,
|
||||
mBodyNode);
|
||||
mWorld->attachCollisionObject(mGhostObject, mBodyEnt, 1, 0x7FFFFFF);
|
||||
mController = new Ogre::Bullet::KinematicMotionSimple(mGhostObject,
|
||||
mBodyNode);
|
||||
OgreAssert(mGhostObject, "Need GhostObject");
|
||||
OgreAssert(mController, "Need controller");
|
||||
mWorld->getBtWorld()->addAction(mController);
|
||||
@@ -380,6 +378,7 @@ void CharacterController::setupAnimations()
|
||||
}
|
||||
bool CharacterController::keyPressed(const OgreBites::KeyboardEvent &evt)
|
||||
{
|
||||
ECS::Input &input = ECS::get().get_mut<ECS::Input>();
|
||||
OgreBites::Keycode key = evt.keysym.sym;
|
||||
if (key == 'q' && (mAnimID == ANIM_IDLE)) {
|
||||
/* ... */
|
||||
@@ -551,10 +550,9 @@ void CharacterController::updateAnimations(Ogre::Real delta)
|
||||
}
|
||||
fadeAnimations(delta);
|
||||
}
|
||||
struct EntityCollisionListener
|
||||
{
|
||||
const Ogre::MovableObject* entity;
|
||||
Ogre::Bullet::CollisionListener* listener;
|
||||
struct EntityCollisionListener {
|
||||
const Ogre::MovableObject *entity;
|
||||
Ogre::Bullet::CollisionListener *listener;
|
||||
};
|
||||
void CharacterController::updateRootMotion(Ogre::Real delta)
|
||||
{
|
||||
@@ -572,7 +570,8 @@ void CharacterController::updateRootMotion(Ogre::Real delta)
|
||||
gvelocity += gravity * delta;
|
||||
velocity += gvelocity;
|
||||
Ogre::Vector3 rotMotion = velocity * delta;
|
||||
btVector3 currentPosition = mGhostObject->getWorldTransform().getOrigin();
|
||||
btVector3 currentPosition =
|
||||
mGhostObject->getWorldTransform().getOrigin();
|
||||
is_on_floor = mController->isOnFloor();
|
||||
penetration = mController->isPenetrating();
|
||||
if (is_on_floor)
|
||||
|
||||
5
src/gamedata/CMakeLists.txt
Normal file
5
src/gamedata/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
project(gamedata)
|
||||
find_package(OGRE REQUIRED COMPONENTS Bites Bullet Paging Terrain CONFIG)
|
||||
add_library(GameData STATIC GameData.cpp)
|
||||
target_link_libraries(GameData PUBLIC OgreMain OgreBullet flecs::flecs_static)
|
||||
target_include_directories(GameData PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
29
src/gamedata/GameData.cpp
Normal file
29
src/gamedata/GameData.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <Ogre.h>
|
||||
#include "GameData.h"
|
||||
|
||||
namespace ECS
|
||||
{
|
||||
static flecs::world ecs;
|
||||
CharacterModule::CharacterModule(flecs::world &ecs)
|
||||
{
|
||||
ecs.component<Input>();
|
||||
ecs.add<Input>();
|
||||
ecs.system("HandleInput").kind(flecs::OnUpdate).run([](flecs::iter &it) {
|
||||
/* handle input */
|
||||
});
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
ecs.add<GameData>();
|
||||
ecs.import <CharacterModule>();
|
||||
}
|
||||
void update(float delta)
|
||||
{
|
||||
ecs.progress(delta);
|
||||
}
|
||||
flecs::world &get()
|
||||
{
|
||||
return ecs;
|
||||
}
|
||||
}
|
||||
36
src/gamedata/GameData.h
Normal file
36
src/gamedata/GameData.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef GAMEDATA_H
|
||||
#define GAMEDATA_H
|
||||
#include <OgreBullet.h>
|
||||
#include <flecs.h>
|
||||
namespace ECS
|
||||
{
|
||||
struct GameData {
|
||||
flecs::entity player;
|
||||
};
|
||||
struct Vector3 {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
};
|
||||
struct Input {
|
||||
Vector3 motion;
|
||||
bool fast;
|
||||
Input()
|
||||
: motion({ 0, 0, 0 })
|
||||
, fast(false)
|
||||
{
|
||||
}
|
||||
};
|
||||
struct CharacterBody {
|
||||
btPairCachingGhostObject *mGhostObject;
|
||||
btCompoundShape *mCollisionShape;
|
||||
Ogre::Bullet::DynamicsWorld *mWorld;
|
||||
};
|
||||
struct CharacterModule {
|
||||
CharacterModule(flecs::world &ecs);
|
||||
};
|
||||
void setup();
|
||||
void update(float delta);
|
||||
flecs::world &get();
|
||||
}
|
||||
#endif
|
||||
3
src/miniaudio/CMakeLists.txt
Normal file
3
src/miniaudio/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
project(miniaudio)
|
||||
add_library(miniaudio STATIC miniaudio.c)
|
||||
target_include_directories(miniaudio PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
2
src/miniaudio/miniaudio.c
Normal file
2
src/miniaudio/miniaudio.c
Normal file
@@ -0,0 +1,2 @@
|
||||
#define MINIAUDIO_IMPLEMENTATION
|
||||
#include "miniaudio.h"
|
||||
95648
src/miniaudio/miniaudio.h
Normal file
95648
src/miniaudio/miniaudio.h
Normal file
File diff suppressed because it is too large
Load Diff
5
src/sound/CMakeLists.txt
Normal file
5
src/sound/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
project(sound)
|
||||
find_package(OGRE REQUIRED COMPONENTS Bites Bullet Paging Terrain CONFIG)
|
||||
add_library(sound STATIC sound.cpp)
|
||||
target_link_libraries(sound PRIVATE miniaudio PUBLIC OgreMain)
|
||||
target_include_directories(sound PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
47
src/sound/sound.cpp
Normal file
47
src/sound/sound.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <iostream>
|
||||
#include <miniaudio.h>
|
||||
#include <Ogre.h>
|
||||
#include <OgreResourceGroupManager.h>
|
||||
#include "sound.h"
|
||||
namespace Sound
|
||||
{
|
||||
static ma_decoder decoder;
|
||||
static ma_device_config deviceConfig;
|
||||
static ma_device device;
|
||||
static ma_engine engine;
|
||||
std::vector<ma_sound> psound_data;
|
||||
std::map<Ogre::String, int> psounds;
|
||||
|
||||
void setup()
|
||||
{
|
||||
int i;
|
||||
ma_result result;
|
||||
result = ma_engine_init(NULL, &engine);
|
||||
OgreAssert(result == MA_SUCCESS, "MiniAudio init failed");
|
||||
Ogre::FileInfoListPtr sounds =
|
||||
Ogre::ResourceGroupManager::getSingleton().findResourceFileInfo(
|
||||
"Audio", "*.wav");
|
||||
psound_data.resize(sounds->size());
|
||||
for (i = 0; i < sounds->size(); i++) {
|
||||
Ogre::FileInfo fi = sounds->at(i);
|
||||
Ogre::String path =
|
||||
fi.archive->getName() + "/" + fi.path + fi.filename;
|
||||
std::cout << "sound: " << path << "\n";
|
||||
std::cout << "sound: " << fi.basename << "\n";
|
||||
ma_sound_init_from_file(&engine, path.c_str(), 0, NULL, NULL,
|
||||
&psound_data[i]);
|
||||
psounds[fi.basename] = i;
|
||||
}
|
||||
}
|
||||
void ding()
|
||||
{
|
||||
ma_sound &sound = psound_data[psounds["load.wav"]];
|
||||
if (ma_sound_is_playing(&sound) && ma_sound_at_end(&sound)) {
|
||||
ma_sound_stop(&sound);
|
||||
ma_sound_seek_to_pcm_frame(&sound, 0);
|
||||
} else if (ma_sound_is_playing(&sound))
|
||||
return;
|
||||
ma_sound_start(&sound);
|
||||
}
|
||||
}
|
||||
/* nothing */
|
||||
8
src/sound/sound.h
Normal file
8
src/sound/sound.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef SOUND_H_
|
||||
#define SOUND_H_
|
||||
namespace Sound
|
||||
{
|
||||
void setup();
|
||||
void ding();
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user