fixes + start working on fighting game sample script

This commit is contained in:
turanszkij
2019-04-18 19:38:40 +01:00
20 changed files with 753 additions and 30 deletions
+6 -1
View File
@@ -358,6 +358,9 @@ Describes an orientation in 3D space.
- Play()
- Stop()
- Pause()
- SetLooped(bool value)
- IsLooped() : bool result
- IsPlaying() : bool result
#### MaterialComponent
- SetBaseColor()
@@ -384,7 +387,9 @@ This is the main entry point and manages the lifetime of the application. Even t
- GetContent() : Resource? result
- GetActivePath() : RenderPath? result
- SetActivePath(RenderPath path, opt float fadeSeconds,fadeColorR,fadeColorG,fadeColorB)
- SetFrameSkip(bool enabled)
- SetFrameSkip(bool enabled) -- enable/disable frame skipping in fixed update
- SetTargetFrameRate(float fps) -- set target frame rate for fixed update and variable rate update when frame rate is locked
- SetFrameRateLock(bool enabled) -- if enabled, variable rate update will use a fixed delta time
- SetInfoDisplay(bool active)
- SetWatermarkDisplay(bool active)
- SetFPSDisplay(bool active)
+2 -2
View File
@@ -72,7 +72,7 @@ ForceFieldWindow::ForceFieldWindow(wiGUI* gui) : GUI(gui)
ForceFieldComponent* force = wiSceneSystem::GetScene().forces.GetComponent(entity);
if (force != nullptr)
{
force->range = args.fValue;
force->range_local = args.fValue;
}
});
rangeSlider->SetEnabled(false);
@@ -119,7 +119,7 @@ void ForceFieldWindow::SetEntity(Entity entity)
{
typeComboBox->SetSelected(force->type == ENTITY_TYPE_FORCEFIELD_POINT ? 0 : 1);
gravitySlider->SetValue(force->gravity);
rangeSlider->SetValue(force->range);
rangeSlider->SetValue(force->range_local);
forceFieldWindow->SetEnabled(true);
}
+2 -2
View File
@@ -42,7 +42,7 @@ LightWindow::LightWindow(wiGUI* gui) : GUI(gui)
LightComponent* light = wiSceneSystem::GetScene().lights.GetComponent(entity);
if (light != nullptr)
{
light->range = args.fValue;
light->range_local = args.fValue;
}
});
rangeSlider->SetEnabled(false);
@@ -246,7 +246,7 @@ void LightWindow::SetEntity(Entity entity)
//lightWindow->SetEnabled(true);
energySlider->SetEnabled(true);
energySlider->SetValue(light->energy);
rangeSlider->SetValue(light->range);
rangeSlider->SetValue(light->range_local);
radiusSlider->SetValue(light->radius);
widthSlider->SetValue(light->width);
heightSlider->SetValue(light->height);
+8 -1
View File
@@ -123,7 +123,14 @@ void MainComponent::Run()
wiProfiler::BeginFrame();
wiProfiler::BeginRange("CPU Frame", wiProfiler::DOMAIN_CPU);
deltaTime = float(max(0, timer.elapsed() / 1000.0));
if (framerate_lock)
{
deltaTime = 1.0f / targetFrameRate;
}
else
{
deltaTime = float(max(0, timer.elapsed() / 1000.0));
}
timer.record();
if (wiWindowRegistration::IsWindowActive())
+2
View File
@@ -13,6 +13,7 @@ protected:
RenderPath* activePath = nullptr;
float targetFrameRate = 60;
bool frameskip = true;
bool framerate_lock = false;
bool initialized = false;
wiFadeManager fadeManager;
@@ -44,6 +45,7 @@ public:
// enabled : the FixedUpdate() loop will run at targetFrameRate frequency
// disabled : the FixedUpdate() loop will run every frame only once.
void setFrameSkip(bool enabled) { frameskip = enabled; }
void setFrameRateLock(bool enabled) { framerate_lock = enabled; }
// This is where the critical initializations happen (before any rendering or anything else)
virtual void Initialize();
+36
View File
@@ -17,6 +17,8 @@ Luna<MainComponent_BindLua>::FunctionType MainComponent_BindLua::methods[] = {
lunamethod(MainComponent_BindLua, GetActivePath),
lunamethod(MainComponent_BindLua, SetActivePath),
lunamethod(MainComponent_BindLua, SetFrameSkip),
lunamethod(MainComponent_BindLua, SetTargetFrameRate),
lunamethod(MainComponent_BindLua, SetFrameRateLock),
lunamethod(MainComponent_BindLua, SetInfoDisplay),
lunamethod(MainComponent_BindLua, SetWatermarkDisplay),
lunamethod(MainComponent_BindLua, SetFPSDisplay),
@@ -235,6 +237,40 @@ int MainComponent_BindLua::SetFrameSkip(lua_State *L)
wiLua::SError(L, "SetFrameSkip(bool enabled) not enought arguments!");
return 0;
}
int MainComponent_BindLua::SetTargetFrameRate(lua_State *L)
{
if (component == nullptr)
{
wiLua::SError(L, "SetTargetFrameRate(float value) component is empty!");
return 0;
}
int argc = wiLua::SGetArgCount(L);
if (argc > 0)
{
component->setTargetFrameRate(wiLua::SGetFloat(L, 1));
}
else
wiLua::SError(L, "SetTargetFrameRate(float value) not enought arguments!");
return 0;
}
int MainComponent_BindLua::SetFrameRateLock(lua_State *L)
{
if (component == nullptr)
{
wiLua::SError(L, "SetFrameRateLock(bool enabled) component is empty!");
return 0;
}
int argc = wiLua::SGetArgCount(L);
if (argc > 0)
{
component->setFrameRateLock(wiLua::SGetBool(L, 1));
}
else
wiLua::SError(L, "SetFrameRateLock(bool enabled) not enought arguments!");
return 0;
}
int MainComponent_BindLua::SetInfoDisplay(lua_State *L)
{
if (component == nullptr)
+2
View File
@@ -20,6 +20,8 @@ public:
int GetActivePath(lua_State *L);
int SetActivePath(lua_State *L);
int SetFrameSkip(lua_State *L);
int SetTargetFrameRate(lua_State *L);
int SetFrameRateLock(lua_State *L);
int SetInfoDisplay(lua_State *L);
int SetWatermarkDisplay(lua_State *L);
int SetFPSDisplay(lua_State *L);
@@ -727,6 +727,7 @@
<None Include="$(MSBuildThisFileDirectory)..\scripts\debug_draw.lua" />
<None Include="$(MSBuildThisFileDirectory)..\scripts\dungeon_generator.lua" />
<None Include="$(MSBuildThisFileDirectory)..\scripts\emitter_burst.lua" />
<None Include="$(MSBuildThisFileDirectory)..\scripts\fighting_game.lua" />
<None Include="$(MSBuildThisFileDirectory)..\scripts\move_object.lua" />
<None Include="$(MSBuildThisFileDirectory)..\scripts\pick.lua" />
<None Include="$(MSBuildThisFileDirectory)..\scripts\rotate_model.lua" />
@@ -1978,6 +1978,9 @@
<None Include="$(MSBuildThisFileDirectory)..\scripts\set_material_emissive.lua">
<Filter>scripts</Filter>
</None>
<None Include="$(MSBuildThisFileDirectory)..\scripts\fighting_game.lua">
<Filter>scripts</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Xml Include="$(MSBuildThisFileDirectory)..\Documentation\OrderOfExecution.xml">
+14 -14
View File
@@ -1235,7 +1235,7 @@ struct SHCAM
void CreateSpotLightShadowCam(const LightComponent& light, SHCAM& shcam)
{
const float zNearP = 0.1f;
const float zFarP = max(1.0f, light.range);
const float zFarP = max(1.0f, light.GetRange());
shcam = SHCAM(XMFLOAT4(0, 0, 0, 1), zNearP, zFarP, light.fov);
shcam.Update(XMMatrixRotationQuaternion(XMLoadFloat4(&light.rotation)) *
XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)));
@@ -3967,7 +3967,7 @@ void UpdateRenderData(GRAPHICSTHREAD threadID)
entityArray[entityCounter].SetType(light.GetType());
entityArray[entityCounter].positionWS = light.position;
XMStoreFloat3(&entityArray[entityCounter].positionVS, XMVector3TransformCoord(XMLoadFloat3(&entityArray[entityCounter].positionWS), viewMatrix));
entityArray[entityCounter].range = light.range;
entityArray[entityCounter].range = light.GetRange();
entityArray[entityCounter].color = wiMath::CompressColor(light.color);
entityArray[entityCounter].energy = light.energy;
entityArray[entityCounter].shadowBias = light.shadowBias;
@@ -4055,8 +4055,8 @@ void UpdateRenderData(GRAPHICSTHREAD threadID)
entityArray[entityCounter].SetType(force.type);
entityArray[entityCounter].positionWS = force.position;
entityArray[entityCounter].energy = force.gravity;
entityArray[entityCounter].range = 1.0f / max(0.0001f, force.range); // avoid division in shader
entityArray[entityCounter].coneAngleCos = force.range; // this will be the real range in the less common shaders...
entityArray[entityCounter].range = 1.0f / max(0.0001f, force.GetRange()); // avoid division in shader
entityArray[entityCounter].coneAngleCos = force.GetRange(); // this will be the real range in the less common shaders...
// The default planar force field is facing upwards, and thus the pull direction is downwards:
entityArray[entityCounter].directionWS = force.direction;
@@ -4531,7 +4531,7 @@ void DrawLights(const CameraComponent& camera, GRAPHICSTHREAD threadID)
{
MiscCB miscCb;
miscCb.g_xColor.x = float(entityArrayOffset_Lights + i);
float sca = light.range + 1;
float sca = light.GetRange() + 1;
XMStoreFloat4x4(&miscCb.g_xTransform, XMMatrixTranspose(XMMatrixScaling(sca, sca, sca)*XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) * camera.GetViewProjection()));
device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, threadID);
device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID);
@@ -4546,7 +4546,7 @@ void DrawLights(const CameraComponent& camera, GRAPHICSTHREAD threadID)
miscCb.g_xColor.x = float(entityArrayOffset_Lights + i);
const float coneS = (const float)(light.fov / XM_PIDIV4);
XMStoreFloat4x4(&miscCb.g_xTransform, XMMatrixTranspose(
XMMatrixScaling(coneS*light.range, light.range, coneS*light.range)*
XMMatrixScaling(coneS*light.GetRange(), light.GetRange(), coneS*light.GetRange())*
XMMatrixRotationQuaternion(XMLoadFloat4(&light.rotation))*
XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) *
camera.GetViewProjection()
@@ -4597,11 +4597,11 @@ void DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHREAD threadID
VolumeLightCB lcb;
lcb.lightColor = XMFLOAT4(light.color.x, light.color.y, light.color.z, 1);
lcb.lightEnerdis = XMFLOAT4(light.energy, light.range, light.fov, light.energy);
lcb.lightEnerdis = XMFLOAT4(light.energy, light.GetRange(), light.fov, light.energy);
if (type == LightComponent::POINT)
{
lcb.lightEnerdis.w = light.range*light.energy*0.01f; // scale
lcb.lightEnerdis.w = light.GetRange()*light.energy*0.01f; // scale
XMStoreFloat4x4(&lcb.lightWorld, XMMatrixTranspose(
XMMatrixScaling(lcb.lightEnerdis.w, lcb.lightEnerdis.w, lcb.lightEnerdis.w)*
camrot*
@@ -4615,7 +4615,7 @@ void DrawLightVisualizers(const CameraComponent& camera, GRAPHICSTHREAD threadID
else if (type == LightComponent::SPOT)
{
float coneS = (float)(light.fov / 0.7853981852531433);
lcb.lightEnerdis.w = light.range*light.energy*0.03f; // scale
lcb.lightEnerdis.w = light.GetRange()*light.energy*0.03f; // scale
XMStoreFloat4x4(&lcb.lightWorld, XMMatrixTranspose(
XMMatrixScaling(coneS*lcb.lightEnerdis.w, lcb.lightEnerdis.w, coneS*lcb.lightEnerdis.w)*
XMMatrixRotationQuaternion(XMLoadFloat4(&light.rotation))*
@@ -4737,7 +4737,7 @@ void DrawVolumeLights(const CameraComponent& camera, GRAPHICSTHREAD threadID)
{
MiscCB miscCb;
miscCb.g_xColor.x = float(entityArrayOffset_Lights + i);
float sca = light.range + 1;
float sca = light.GetRange() + 1;
XMStoreFloat4x4(&miscCb.g_xTransform, XMMatrixTranspose(XMMatrixScaling(sca, sca, sca)*XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) * camera.GetViewProjection()));
device->UpdateBuffer(&constantBuffers[CBTYPE_MISC], &miscCb, threadID);
device->BindConstantBuffer(VS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID);
@@ -4752,7 +4752,7 @@ void DrawVolumeLights(const CameraComponent& camera, GRAPHICSTHREAD threadID)
miscCb.g_xColor.x = float(entityArrayOffset_Lights + i);
const float coneS = (const float)(light.fov / XM_PIDIV4);
XMStoreFloat4x4(&miscCb.g_xTransform, XMMatrixTranspose(
XMMatrixScaling(coneS*light.range, light.range, coneS*light.range)*
XMMatrixScaling(coneS*light.GetRange(), light.GetRange(), coneS*light.GetRange())*
XMMatrixRotationQuaternion(XMLoadFloat4(&light.rotation))*
XMMatrixTranslationFromVector(XMLoadFloat3(&light.position)) *
camera.GetViewProjection()
@@ -5059,7 +5059,7 @@ void DrawForShadowMap(const CameraComponent& camera, GRAPHICSTHREAD threadID, ui
SHCAM shcam;
CreateSpotLightShadowCam(light, shcam);
const float zFarP = max(1.0f, light.range);
const float zFarP = max(1.0f, light.GetRange());
Frustum frustum;
frustum.Create(shcam.realProjection, shcam.View, zFarP);
@@ -5137,7 +5137,7 @@ void DrawForShadowMap(const CameraComponent& camera, GRAPHICSTHREAD threadID, ui
for (size_t i = 0; i < scene.aabb_objects.GetCount(); ++i)
{
const AABB& aabb = scene.aabb_objects[i];
if (SPHERE(light.position, light.range).intersects(aabb))
if (SPHERE(light.position, light.GetRange()).intersects(aabb))
{
const ObjectComponent& object = scene.objects[i];
if (object.IsRenderable() && object.IsCastingShadow() && object.GetRenderTypes() == RENDERTYPE_OPAQUE)
@@ -5171,7 +5171,7 @@ void DrawForShadowMap(const CameraComponent& camera, GRAPHICSTHREAD threadID, ui
device->BindConstantBuffer(PS, &constantBuffers[CBTYPE_MISC], CB_GETBINDSLOT(MiscCB), threadID);
const float zNearP = 0.1f;
const float zFarP = max(1.0f, light.range);
const float zFarP = max(1.0f, light.GetRange());
SHCAM cameras[] = {
SHCAM(XMFLOAT4(0.5f, -0.5f, -0.5f, -0.5f), zNearP, zFarP, XM_PIDIV2), //+x
SHCAM(XMFLOAT4(0.5f, 0.5f, 0.5f, -0.5f), zNearP, zFarP, XM_PIDIV2), //-x
+6 -6
View File
@@ -1245,7 +1245,7 @@ namespace wiSceneSystem
LightComponent& light = lights.Create(entity);
light.energy = energy;
light.range = range;
light.range_local = range;
light.fov = XM_PIDIV4;
light.color = color;
light.SetType(LightComponent::POINT);
@@ -1269,7 +1269,7 @@ namespace wiSceneSystem
ForceFieldComponent& force = forces.Create(entity);
force.gravity = 0;
force.range = 0;
force.range_local = 0;
force.type = ENTITY_TYPE_FORCEFIELD_POINT;
return entity;
@@ -1972,7 +1972,7 @@ namespace wiSceneSystem
XMStoreFloat3(&force.position, T);
XMStoreFloat3(&force.direction, XMVector3Normalize(XMVector3TransformNormal(XMVectorSet(0, -1, 0, 0), W)));
force.range = force.range_local * max(XMVectorGetX(S), max(XMVectorGetY(S), XMVectorGetZ(S)));
force.range_global = force.range_local * max(XMVectorGetX(S), max(XMVectorGetY(S), XMVectorGetZ(S)));
});
}
void RunLightUpdateSystem(
@@ -1998,7 +1998,7 @@ namespace wiSceneSystem
XMStoreFloat4(&light.rotation, R);
XMStoreFloat3(&light.direction, XMVector3TransformNormal(XMVectorSet(0, 1, 0, 0), W));
light.range = light.range_local * max(XMVectorGetX(S), max(XMVectorGetY(S), XMVectorGetZ(S)));
light.range_global = light.range_local * max(XMVectorGetX(S), max(XMVectorGetY(S), XMVectorGetZ(S)));
switch (light.type)
{
@@ -2006,10 +2006,10 @@ namespace wiSceneSystem
aabb.createFromHalfWidth(wiRenderer::GetCamera().Eye, XMFLOAT3(10000, 10000, 10000));
break;
case LightComponent::SPOT:
aabb.createFromHalfWidth(light.position, XMFLOAT3(light.range, light.range, light.range));
aabb.createFromHalfWidth(light.position, XMFLOAT3(light.GetRange(), light.GetRange(), light.GetRange()));
break;
case LightComponent::POINT:
aabb.createFromHalfWidth(light.position, XMFLOAT3(light.range, light.range, light.range));
aabb.createFromHalfWidth(light.position, XMFLOAT3(light.GetRange(), light.GetRange(), light.GetRange()));
break;
case LightComponent::SPHERE:
case LightComponent::DISC:
+6 -3
View File
@@ -662,7 +662,7 @@ namespace wiSceneSystem
// Non-serialized attributes:
XMFLOAT3 position;
float range;
float range_global;
XMFLOAT3 direction;
XMFLOAT4 rotation;
XMFLOAT3 front;
@@ -681,7 +681,7 @@ namespace wiSceneSystem
inline bool IsVisualizerEnabled() const { return _flags & VISUALIZER; }
inline bool IsStatic() const { return _flags & LIGHTMAPONLY_STATIC; }
inline float GetRange() const { return range; }
inline float GetRange() const { return range_global; }
inline void SetType(LightType val) {
type = val;
@@ -792,9 +792,11 @@ namespace wiSceneSystem
// Non-serialized attributes:
XMFLOAT3 position;
float range;
float range_global;
XMFLOAT3 direction;
inline float GetRange() const { return range_global; }
void Serialize(wiArchive& archive, uint32_t seed = 0);
};
@@ -881,6 +883,7 @@ namespace wiSceneSystem
inline bool IsPlaying() const { return _flags & PLAYING; }
inline bool IsLooped() const { return _flags & LOOPED; }
inline float GetLength() const { return end - start; }
inline bool IsEnded() const { return timer >= end; }
inline void Play() { _flags |= PLAYING; }
inline void Pause() { _flags &= ~PLAYING; }
+33
View File
@@ -987,6 +987,10 @@ Luna<AnimationComponent_BindLua>::FunctionType AnimationComponent_BindLua::metho
lunamethod(AnimationComponent_BindLua, Play),
lunamethod(AnimationComponent_BindLua, Pause),
lunamethod(AnimationComponent_BindLua, Stop),
lunamethod(AnimationComponent_BindLua, SetLooped),
lunamethod(AnimationComponent_BindLua, IsLooped),
lunamethod(AnimationComponent_BindLua, IsPlaying),
lunamethod(AnimationComponent_BindLua, IsEnded),
{ NULL, NULL }
};
Luna<AnimationComponent_BindLua>::PropertyType AnimationComponent_BindLua::properties[] = {
@@ -1021,6 +1025,35 @@ int AnimationComponent_BindLua::Stop(lua_State* L)
component->Stop();
return 0;
}
int AnimationComponent_BindLua::SetLooped(lua_State* L)
{
int argc = wiLua::SGetArgCount(L);
if (argc > 0)
{
bool looped = wiLua::SGetBool(L, 1);
component->SetLooped(looped);
}
else
{
wiLua::SError(L, "SetLooped(bool value) not enough arguments!");
}
return 0;
}
int AnimationComponent_BindLua::IsLooped(lua_State* L)
{
wiLua::SSetBool(L, component->IsLooped());
return 1;
}
int AnimationComponent_BindLua::IsPlaying(lua_State* L)
{
wiLua::SSetBool(L, component->IsPlaying());
return 1;
}
int AnimationComponent_BindLua::IsEnded(lua_State* L)
{
wiLua::SSetBool(L, component->IsEnded());
return 1;
}
+4
View File
@@ -152,6 +152,10 @@ namespace wiSceneSystem_BindLua
int Play(lua_State* L);
int Pause(lua_State* L);
int Stop(lua_State* L);
int SetLooped(lua_State* L);
int IsLooped(lua_State* L);
int IsPlaying(lua_State* L);
int IsEnded(lua_State* L);
};
class MaterialComponent_BindLua
+1 -1
View File
@@ -9,7 +9,7 @@ namespace wiVersion
// minor features, major updates
const int minor = 26;
// minor bug fixes, alterations, refactors, updates
const int revision = 10;
const int revision = 11;
long GetVersion()
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 MiB

Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.
File diff suppressed because it is too large Load Diff