Bigger
This commit is contained in:
@@ -5,7 +5,8 @@
|
||||
|
||||
REGISTER_ENTITY(ActorBase);
|
||||
|
||||
ActorBase::ActorBase()
|
||||
ActorBase::ActorBase() :
|
||||
m_noclip(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -242,6 +243,40 @@ bool ActorBase::OnGround()
|
||||
return false;
|
||||
}
|
||||
|
||||
void ActorBase::SetNoclip(bool noclip)
|
||||
{
|
||||
static int mask1 = -1, mask2 = -1;
|
||||
|
||||
m_noclip = noclip;
|
||||
|
||||
if (noclip)
|
||||
{
|
||||
if (mask1 == -1)
|
||||
{
|
||||
mask1 = m_rigidBody->getBroadphaseHandle()->m_collisionFilterGroup;
|
||||
mask2 = m_rigidBody->getBroadphaseHandle()->m_collisionFilterMask;
|
||||
}
|
||||
|
||||
m_rigidBody->getBroadphaseHandle()->m_collisionFilterGroup = 0;
|
||||
m_rigidBody->getBroadphaseHandle()->m_collisionFilterMask = 0;
|
||||
|
||||
g_PhysicsWorld->GetWorld()->getPairCache()->cleanProxyFromPairs(m_rigidBody->getBroadphaseHandle(), g_PhysicsWorld->GetWorld()->getDispatcher());
|
||||
|
||||
m_rigidBody->setCollisionFlags(m_rigidBody->getCollisionFlags() |/* btCollisionObject::CF_KINEMATIC_OBJECT |*/ btCollisionObject::CF_NO_CONTACT_RESPONSE);
|
||||
m_rigidBody->setGravity(btVector3(0.0f, 0.f, 0.f));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
m_rigidBody->getBroadphaseHandle()->m_collisionFilterGroup = mask1;
|
||||
m_rigidBody->getBroadphaseHandle()->m_collisionFilterMask = mask2;
|
||||
|
||||
// m_rigidBody->setCollisionFlags(m_rigidBody->getCollisionFlags() & ~btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||
m_rigidBody->setCollisionFlags(m_rigidBody->getCollisionFlags() & ~btCollisionObject::CF_NO_CONTACT_RESPONSE);
|
||||
m_rigidBody->setGravity(g_PhysicsWorld->GetWorld()->getGravity());
|
||||
}
|
||||
}
|
||||
|
||||
void ActorBase::RegisterFunctions()
|
||||
{
|
||||
m_luaObject.Register("activate_camera", *this, &ActorBase::Lua_ActivateCamera);
|
||||
@@ -253,6 +288,7 @@ void ActorBase::RegisterFunctions()
|
||||
m_luaObject.Register("get_action", *this, &ActorBase::Lua_GetAction);
|
||||
m_luaObject.Register("get_movement", *this, &ActorBase::Lua_GetMovement);
|
||||
m_luaObject.Register("on_ground", *this, &ActorBase::Lua_OnGround);
|
||||
m_luaObject.Register("is_noclip", *this, &ActorBase::Lua_IsNoclip);
|
||||
|
||||
//m_luaObject.RegisterDirect("activate_camera", &ActorBase_ActivateCamera);
|
||||
//m_luaObject.RegisterDirect("update_camera_look", &ActorBase_UpdateCameraLook);
|
||||
@@ -332,6 +368,12 @@ int ActorBase::Lua_OnGround(LuaPlus::LuaState* state)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ActorBase::Lua_IsNoclip(LuaPlus::LuaState* state)
|
||||
{
|
||||
state->PushBoolean(m_noclip);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ActorBase::GenAction()
|
||||
{
|
||||
int action = -1;
|
||||
|
||||
@@ -37,6 +37,8 @@ public:
|
||||
|
||||
bool OnGround();
|
||||
|
||||
void SetNoclip(bool noclip);
|
||||
|
||||
// Lua bindings
|
||||
|
||||
virtual void RegisterFunctions();
|
||||
@@ -50,6 +52,7 @@ public:
|
||||
int Lua_GetAction(LuaPlus::LuaState* state);
|
||||
int Lua_GetMovement(LuaPlus::LuaState* state);
|
||||
int Lua_OnGround(LuaPlus::LuaState* state);
|
||||
int Lua_IsNoclip(LuaPlus::LuaState* state);
|
||||
|
||||
private:
|
||||
int GenAction();
|
||||
@@ -58,7 +61,7 @@ private:
|
||||
private:
|
||||
Camera m_camera;
|
||||
|
||||
|
||||
bool m_noclip;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
#include "world.h"
|
||||
#include "game_object.h"
|
||||
#include "soundsystem.h"
|
||||
#include "animation.h"
|
||||
#include "scenemanager.h"
|
||||
#include "game_world_objects.h"
|
||||
#include "actor_base.h"
|
||||
|
||||
#include <pugixml.hpp>
|
||||
|
||||
@@ -27,6 +31,7 @@ public:
|
||||
|
||||
public:
|
||||
void PlaySound2D(const std::string& filename);
|
||||
void PlaySound3D(const std::string& filename, const glm::vec3& pos);
|
||||
void CacheSound(const std::string& filename);
|
||||
|
||||
private:
|
||||
@@ -57,6 +62,24 @@ void GameSoundSystem::PlaySound2D(const std::string& filename)
|
||||
g_soundSystem.Play(it->second, false);
|
||||
}
|
||||
|
||||
void GameSoundSystem::PlaySound3D(const std::string& filename, const glm::vec3& pos)
|
||||
{
|
||||
auto it = m_sounds.find(filename);
|
||||
if (it == m_sounds.end())
|
||||
{
|
||||
CacheSound(filename);
|
||||
it = m_sounds.find(filename);
|
||||
}
|
||||
|
||||
SDL_assert(it != m_sounds.end());
|
||||
|
||||
// .hack due unimplemented sound sources^
|
||||
if (g_soundSystem.IsPlaying(it->second))
|
||||
g_soundSystem.Stop(it->second);
|
||||
|
||||
g_soundSystem.Play3D(it->second, pos.x, pos.y, pos.z, true);
|
||||
}
|
||||
|
||||
void GameSoundSystem::CacheSound(const std::string& filename)
|
||||
{
|
||||
m_sounds.emplace(filename, g_soundSystem.LoadSound(filename.c_str()));
|
||||
@@ -82,6 +105,11 @@ void enginePlaySound(const char* filename)
|
||||
GameSoundSystem::GetInstance().PlaySound2D(filename);
|
||||
}
|
||||
|
||||
void enginePlaySound3D(const char* filename, float x, float y, float z)
|
||||
{
|
||||
GameSoundSystem::GetInstance().PlaySound3D(filename, glm::vec3(x, y, z));
|
||||
}
|
||||
|
||||
LuaPlus::LuaObject engineCreateEntity(const char* classname)
|
||||
{
|
||||
Entity* entity = static_cast<Entity*>(g_game->Lua_CreateEntity(classname));
|
||||
@@ -157,6 +185,7 @@ void registerEngine()
|
||||
engineTable.RegisterDirect("add_entity_to_world", &engineAddEntityToWorld);
|
||||
engineTable.RegisterDirect("get_entity_from_id", &engineGetEntityFromID);
|
||||
engineTable.RegisterDirect("play_sound", &enginePlaySound);
|
||||
engineTable.RegisterDirect("play_sound_3d", &enginePlaySound3D);
|
||||
engineTable.RegisterDirect("get_delta", &engineGetDelta);
|
||||
engineTable.RegisterDirect("trace_ray", &engineTraceRay);
|
||||
|
||||
@@ -231,6 +260,20 @@ void registerInput()
|
||||
inputTable.RegisterDirect("get_lock_mouse", &inputGetLock);
|
||||
}
|
||||
|
||||
void toggleNoclip()
|
||||
{
|
||||
static bool s_noclip = false;
|
||||
|
||||
s_noclip = !s_noclip;
|
||||
|
||||
LuaPlus::LuaObject player = GetLuaState().GetGlobal("g_player");
|
||||
if (player.IsTable())
|
||||
{
|
||||
ActorBase* actor = (ActorBase*)player["__object"].GetLightUserdata();
|
||||
actor->SetNoclip(s_noclip);
|
||||
}
|
||||
}
|
||||
|
||||
int cameraGetPos(LuaPlus::LuaState* state)
|
||||
{
|
||||
glm::vec3 v = glm::vec3(0.0f);
|
||||
@@ -494,6 +537,16 @@ void Game::LoadLevelXML(const char* mapname)
|
||||
entity->LoadModel(filename);
|
||||
}
|
||||
|
||||
pugi::xml_node animation = entitynode.child("Animation");
|
||||
if (animation)
|
||||
{
|
||||
const char* name = animation.attribute("name").as_string();
|
||||
int mode = animation.attribute("mode").as_int();
|
||||
SkeletonInstance* skeleton = entity->GetSkeletonInstance();
|
||||
if (skeleton)
|
||||
skeleton->PlayAnimation(skeleton->FindAnimation(name), mode);
|
||||
}
|
||||
|
||||
pugi::xml_node physics = entitynode.child("Physics");
|
||||
if (physics)
|
||||
{
|
||||
@@ -502,6 +555,10 @@ void Game::LoadLevelXML(const char* mapname)
|
||||
entity->CreateTestBody();
|
||||
}
|
||||
|
||||
Light* light = dynamic_cast<Light*>(entity); // BAD!!!
|
||||
if (light)
|
||||
light->InitFromXML(entitynode);
|
||||
|
||||
entity->Init();
|
||||
|
||||
//IEntityBase* entity = g_entityManager->CreateEntity(classname.as_string());
|
||||
|
||||
@@ -23,8 +23,9 @@ public:
|
||||
|
||||
extern Game* g_game;
|
||||
|
||||
void registerCamera();
|
||||
void registerInput();
|
||||
void toggleNoclip();
|
||||
|
||||
#endif
|
||||
|
||||
void registerCamera();
|
||||
|
||||
void registerInput();
|
||||
|
||||
@@ -134,6 +134,11 @@ bool Entity::GetVisible()
|
||||
return true;
|
||||
}
|
||||
|
||||
SkeletonInstance* Entity::GetSkeletonInstance()
|
||||
{
|
||||
return m_skeleton;
|
||||
}
|
||||
|
||||
void Entity::UpdateSkeleton(float dt)
|
||||
{
|
||||
if (m_model && m_skeleton)
|
||||
|
||||
@@ -77,6 +77,7 @@ public:
|
||||
void SetVisible(bool visible);
|
||||
bool GetVisible();
|
||||
|
||||
SkeletonInstance* GetSkeletonInstance();
|
||||
void UpdateSkeleton(float dt);
|
||||
|
||||
void Init();
|
||||
|
||||
51
src/game/game_world_objects.cpp
Normal file
51
src/game/game_world_objects.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "core.h"
|
||||
#include "game_world_objects.h"
|
||||
#include "debugrender.h"
|
||||
#include "scenemanager.h" // BAD!
|
||||
|
||||
bool g_debugDrawLights = false;
|
||||
|
||||
REGISTER_ENTITY(Light);
|
||||
|
||||
Light::Light()
|
||||
{
|
||||
m_dlight = nullptr;
|
||||
}
|
||||
|
||||
Light::~Light()
|
||||
{
|
||||
}
|
||||
|
||||
void Light::Render()
|
||||
{
|
||||
if (!m_dlight)
|
||||
return;
|
||||
|
||||
m_dlight->position = m_position;
|
||||
|
||||
if (g_debugDrawLights)
|
||||
{
|
||||
g_debugRender->DrawSphere(m_dlight->position, m_dlight->radius, m_dlight->color);
|
||||
}
|
||||
}
|
||||
|
||||
void Light::InitFromXML(const pugi::xml_node& node)
|
||||
{
|
||||
m_dlight = DLightManager::GetInstance()->AllocLight();
|
||||
SDL_assert_always(m_dlight);
|
||||
m_dlight->position = m_position;
|
||||
|
||||
pugi::xml_node color = node.child("Color");
|
||||
if (color)
|
||||
{
|
||||
m_dlight->color.r = color.attribute("r").as_float();
|
||||
m_dlight->color.g = color.attribute("g").as_float();
|
||||
m_dlight->color.b = color.attribute("b").as_float();
|
||||
}
|
||||
|
||||
pugi::xml_node radius = node.child("Radius");
|
||||
if (radius)
|
||||
{
|
||||
m_dlight->radius = radius.attribute("value").as_float();
|
||||
}
|
||||
}
|
||||
26
src/game/game_world_objects.h
Normal file
26
src/game/game_world_objects.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef GAME_WORLD_OBJECTS_H
|
||||
#define GAME_WORLD_OBJECTS_H
|
||||
|
||||
#include <pugixml.hpp>
|
||||
|
||||
#include "game_object.h"
|
||||
|
||||
struct DLight;
|
||||
|
||||
// #TODO: Inheritance from Entity is needed for expose to lua, but did
|
||||
// light need to have a animation stuff?
|
||||
class Light : public Entity
|
||||
{
|
||||
public:
|
||||
Light();
|
||||
~Light();
|
||||
|
||||
void Render() override;
|
||||
|
||||
void InitFromXML(const pugi::xml_node& node);
|
||||
|
||||
private:
|
||||
DLight* m_dlight;
|
||||
};
|
||||
|
||||
#endif // !GAME_WORLD_OBJECTS_H
|
||||
Reference in New Issue
Block a user