This commit is contained in:
2026-03-05 15:20:18 +03:00
parent 70c3459703
commit f8f69d3b88
25 changed files with 261 additions and 31 deletions

View File

@@ -0,0 +1,13 @@
# Blender MTL File: 'None'
# Material Count: 1
newmtl graveyard_terrain
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd data/textures/weapons/handfinal256.bmp

View File

@@ -0,0 +1,13 @@
# Blender MTL File: 'None'
# Material Count: 1
newmtl graveyard_terrain
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd data/textures/weapons/ump.bmp

View File

@@ -0,0 +1,13 @@
# Blender MTL File: 'None'
# Material Count: 1
newmtl graveyard_terrain
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd data/textures/weapons/ump2.bmp

View File

@@ -1,6 +1,8 @@
-- игрок
actor_player = inherit_table(actor_base)
actor_player.m_camera_offset_y = 0.5
function actor_player:on_init()
actor_base.on_init(self)
@@ -14,7 +16,7 @@ function actor_player:on_init()
self.m_weapon_entity_id = ent:get_id()
self.m_in_reload = false
--local ent2 = engine.get_entity_from_id(self.m_weapon_entity_id)
--console.print(ent2:get_classname())
end
@@ -35,14 +37,15 @@ function actor_player:on_update(dt)
if self:get_action() == ACTION_FIRE and self.m_in_reload == false then
ent:play_animation(ent:find_animation("shoot1"), ANIM_PLAYBACK_NONE)
engine.play_sound("data/sounds/weapons/ump45_shoot.wav")
end
if self:get_action() == ACTION_RELOAD and self.m_in_reload == false then
ent:play_animation(ent:find_animation("reload"), ANIM_PLAYBACK_NONE)
self.m_in_reload = true
engine.play_sound("data/sounds/weapons/ump45_reload.wav")
self.m_in_reload = true
end
if ent:get_current_animation() == ent:find_animation("shoot1") and
ent:get_current_animation_time() >= ent:get_animation_time(ent:find_animation("shoot1")) then
ent:play_animation(ent:find_animation("idle1"), ANIM_PLAYBACK_REPEAT)
@@ -61,7 +64,3 @@ end
function actor_player:on_collide(other)
console.print(string.format("actor_player:on_collide: %s", other:get_classname()))
end
function play_sound( filename, is_3d, posx, posy, posz )
-- body
end

65
data/scripts/help.lua Normal file
View File

@@ -0,0 +1,65 @@
Globals:
ACTION_FIRE = 0
ACTION_ALT_FIRE = 1
ACTION_RELOAD = 2
ANIM_PLAYBACK_NONE = 0
ANIM_PLAYBACK_REPEAT = 1
engine.error(string message)
engine.warning(string message)
engine.create_entity(string classname) -- return an table to the new entity
engine.add_entity_to_world(entity) -- add entity to the world
engine.get_entity_from_id(integer id) -- return an entity table from
engine.play_sound(string filename) -- play 2d sound
camera.get_position() -- return x, y, z
camera.get_front() -- return x, y, z
camera.get_right() -- return x, y, z
camera.get_up() -- return float
camera.get_pitch() -- return float
console.print(string message)
Entity properties:
string m_name
integer m_id
Entity methods:
load_model(string filename)
update_transform()
translate(float x, float y, float z) -- addition to the current position
set_position(float x, float y, float z) -- setting the position
get_position() -- return x, y, z
set_rotation(float x, float y, float z) -- setting the euler rotation
set_rotation_from_vectors(float frontx, float fronty, float frontz,
float rightx, float righty, float rightz,
float upx, float upy, float upz) -- rotate around axis
get_classname() -- return the classname of the entity
get_id() -- return the id of the entity
find_animation(string name) -- find a animation in the model
play_animation(integer id, integer mode) -- play a animation with specified mode (ANIM_PLAYBACK_NONE, ANIM_PLAYBACK_REPEAT)
get_current_animation() -- return the id to the current playing animation
get_current_animation_time() -- return the current time of the current playing animation
get_animation_time(integer id) -- return the time of a animation
ActorBase methods:
activate_camera()
update_camera_look()
update_camera_movement(float nubmer)
create_body()
update_body_movement(float nubmer)
get_action() -- return an current mode (ACTION_FIRE, ACTION_ALT_FIRE, ACTION_RELOAD)

View File

@@ -27,10 +27,9 @@ function test_object:set_relative_position_to_camera( ent )
local rightX, rightY, rightZ = camera.get_right()
local upX, upY, upZ = camera.get_up()
local yaw = camera.get_yaw()
local pitch = camera.get_pitch()
self:set_rotation(pitch, -yaw, 0.0)
self:set_rotation_from_vectors(frontX, frontY, frontZ,
rightX, rightY, rightZ,
upX, upY, upZ)
local offsetx = 0.0
local offsety = 0.0

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

View File

@@ -28,7 +28,8 @@ void Camera::SetYawPitch(float yaw, float pitch)
m_front = glm::normalize(m_direction);
m_right = glm::normalize(glm::cross(m_front, m_up));
m_right = glm::normalize(glm::cross(m_front, glm::vec3(0.0f, 1.0f, 0.0f)));
m_up = glm::normalize(glm::cross(m_right, m_front));
}
glm::quat Camera::GetOrientation()

View File

@@ -9,6 +9,7 @@
#include "camera.h"
#include "inputmanager.h"
#include "physics/physicsworld.h"
#include "soundsystem.h"
// renderer
#include "render.h"
@@ -117,6 +118,10 @@ void Engine::Init()
g_entityManager->Init();
// initialize sound system
g_soundSystem.Init();
// Initialize game
g_game->Init();
@@ -135,6 +140,8 @@ void Engine::Shutdown()
g_game->Shutdown();
g_soundSystem.Shutdown();
g_entityManager->Shutdown();
if (g_render) {

View File

@@ -43,11 +43,13 @@ const glm::mat4& IEntityBase::GetWorldTransform()
void IEntityBase::UpdateTransform()
{
glm::vec3 radiansRotation = glm::vec3(glm::radians(m_rotation.x), glm::radians(m_rotation.y), glm::radians(m_rotation.z));
glm::mat4 rotation = glm::toMat4(glm::quat(radiansRotation));
glm::vec3 radiansRotation = glm::radians(m_rotation);
m_worldTM = glm::mat4(1.0f);
m_worldTM = glm::translate(m_worldTM, m_position) * rotation * glm::scale(m_worldTM, m_scale);
glm::mat4 T = glm::translate(glm::mat4(1.0f), m_position);
glm::mat4 R = glm::toMat4(glm::quat(radiansRotation));
glm::mat4 S = glm::scale(glm::mat4(1.0f), m_scale);
m_worldTM = T * R * S;
}
uint32_t IEntityBase::GetID()

View File

@@ -7,12 +7,58 @@
#include "entitymanager.h"
#include "world.h"
#include "game_object.h"
#include "soundsystem.h"
#include <pugixml.hpp>
#include <map>
#include <string>
static Game s_game;
Game* g_game = &s_game;
class GameSoundSystem
{
public:
static GameSoundSystem& GetInstance();
public:
void PlaySound2D(const std::string& filename);
void CacheSound(const std::string& filename);
private:
std::map<std::string, SoundHandle> m_sounds;
};
GameSoundSystem& GameSoundSystem::GetInstance()
{
static GameSoundSystem inst;
return inst;
}
void GameSoundSystem::PlaySound2D(const std::string& filename)
{
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.Play(it->second, false);
}
void GameSoundSystem::CacheSound(const std::string& filename)
{
m_sounds.emplace(filename, g_soundSystem.LoadSound(filename.c_str()));
}
void consoleMsg(const char* msg)
{
Logger::Msg("%s", msg);
@@ -28,6 +74,11 @@ void engineWarning(const char* msg)
Core::Warning("%s", msg);
}
void enginePlaySound(const char* filename)
{
GameSoundSystem::GetInstance().PlaySound2D(filename);
}
LuaPlus::LuaObject engineCreateEntity(const char* classname)
{
Entity* entity = static_cast<Entity*>(g_game->Lua_CreateEntity(classname));
@@ -151,6 +202,7 @@ void registerEngine()
engineTable.RegisterDirect("create_entity", &engineCreateEntity);
engineTable.RegisterDirect("add_entity_to_world", &engineAddEntityToWorld);
engineTable.RegisterDirect("get_entity_from_id", &engineGetEntityFromID);
engineTable.RegisterDirect("play_sound", &enginePlaySound);
LuaObject consoleTable = GetLuaState().GetGlobals().CreateTable("console");
consoleTable.RegisterDirect("print", &consoleMsg);

View File

@@ -236,6 +236,7 @@ void Entity::RegisterBaseFunctions()
m_luaObject.Register("set_position", *this, &Entity::Lua_SetPosition);
m_luaObject.Register("get_position", *this, &Entity::Lua_GetPosition);
m_luaObject.Register("set_rotation", *this, &Entity::Lua_SetRotation);
m_luaObject.Register("set_rotation_from_vectors", *this, &Entity::Lua_SetRotationFromVectors);
m_luaObject.Register("get_classname", *this, &Entity::Lua_GetClassname);
m_luaObject.Register("get_id", *this, &Entity::Lua_GetID);
@@ -282,6 +283,22 @@ void Entity::Help_SetRotation(float x, float y, float z)
m_rotation.z = z;
}
void Entity::Help_SetRotationFromVectors(const glm::vec3& front, const glm::vec3& right, const glm::vec3& up)
{
glm::mat3 rot;
rot[0] = right;
rot[1] = up;
rot[2] = -front;
glm::quat q = glm::quat_cast(rot);
glm::quat fix = glm::angleAxis(glm::radians(90.0f), glm::vec3(0, 1, 0));
q = q * fix;
m_rotation = glm::degrees(glm::eulerAngles(q));
}
int Entity::Lua_LoadModel(LuaPlus::LuaState* state)
{
LuaPlus::LuaStack stack(state);
@@ -345,6 +362,30 @@ int Entity::Lua_SetRotation(LuaPlus::LuaState* state)
return 0;
}
int Entity::Lua_SetRotationFromVectors(LuaPlus::LuaState* state)
{
LuaPlus::LuaStack stack(state);
glm::vec3 front(
stack[2].GetNumber(),
stack[3].GetNumber(),
stack[4].GetNumber());
glm::vec3 right(
stack[5].GetNumber(),
stack[6].GetNumber(),
stack[7].GetNumber());
glm::vec3 up(
stack[8].GetNumber(),
stack[9].GetNumber(),
stack[10].GetNumber());
Help_SetRotationFromVectors(front, right, up);
return 0;
}
int Entity::Lua_GetClassname(LuaPlus::LuaState* state)
{
state->PushString(GetClassname());
@@ -525,7 +566,17 @@ void ActorBase::AfterEngineStep()
//m_position = btVectorToGlm(xform.getOrigin());
m_position = btVectorToGlm(m_ph_motion_state.m_transform.getOrigin());
m_camera.SetPosition(m_position);
glm::vec3 cameraPos = m_position;
if (m_luaObject.IsTable())
{
LuaPlus::LuaObject m_camera_offset_y = m_luaObject.GetByName("m_camera_offset_y");
if (m_camera_offset_y.IsNumber())
cameraPos.y += m_camera_offset_y.ToNumber();
}
m_camera.SetPosition(cameraPos);
}
void ActorBase::UpdateCameraMovement(float dt)

View File

@@ -96,12 +96,14 @@ public:
void Help_Translate(float x, float y, float z);
void Help_SetPosition(float x, float y, float z);
void Help_SetRotation(float x, float y, float z);
void Help_SetRotationFromVectors(const glm::vec3& front, const glm::vec3& right, const glm::vec3& up);
int Lua_LoadModel(LuaPlus::LuaState* state);
int Lua_Translate(LuaPlus::LuaState* state);
int Lua_SetPosition(LuaPlus::LuaState* state);
int Lua_GetPosition(LuaPlus::LuaState* state);
int Lua_SetRotation(LuaPlus::LuaState* state);
int Lua_SetRotationFromVectors(LuaPlus::LuaState* state);
int Lua_GetClassname(LuaPlus::LuaState* state);
int Lua_GetID(LuaPlus::LuaState* state);
int Lua_UpdateTransform(LuaPlus::LuaState* state);

View File

@@ -30,7 +30,6 @@ static std::string getFileNameWithoutExtension(const std::string& filename)
Model::Model()
{
m_AlbedoTexture = nullptr;
m_numPoses = 0;
//m_boundingBox.min = glm::vec3(0.0f);
@@ -39,7 +38,6 @@ Model::Model()
Model::~Model()
{
m_AlbedoTexture = nullptr;
for (int i = 0; i < m_meshes.size(); i++)
ReleaseModelData(m_meshes[i]);
@@ -268,6 +266,8 @@ void Model::LoadIqm(const char* filename)
indices[j * 3 + 2] = a - pMesh->first_vertex;
}
const char* pMaterialname = nullptr;
if (pHdr->ofs_text)
{
// #TODO: weird weird getting material name string is so wrong
@@ -275,8 +275,9 @@ void Model::LoadIqm(const char* filename)
const char* str = (char*)pHdr + pHdr->ofs_text;
const char* materialname = &str[pMesh->material];
//if (materialname)
// pMaterial = g_materialSystem.LoadMaterial(materialname);
if (materialname)
pMaterialname = materialname;
//pMaterial = g_materialSystem.LoadMaterial(materialname);
}
ModelData_t mesh = {};
@@ -286,6 +287,14 @@ void Model::LoadIqm(const char* filename)
mesh.vbcount = pMesh->num_vertexes;
mesh.ib = g_renderDevice->CreateIndexBuffer(indices.data(), pMesh->num_triangles * sizeof(iqmtriangle), false);
mesh.ibcount = pMesh->num_triangles * 3;
std::string mtlfilename = getFileNameWithoutExtension(filename);
mtlfilename += "_";
mtlfilename += pMaterialname;
mtlfilename += ".mtl";
mesh.m_AlbedoTexture = LoadMtl(mtlfilename.c_str());
//mesh.m_material = pMaterial;
//
//if (!mesh.m_material)
@@ -549,17 +558,19 @@ void Model::LoadObj(const char* filename)
std::string mtlfilename = getFileNameWithoutExtension(filename);
mtlfilename += ".mtl";
LoadMtl(mtlfilename.c_str());
m_data.m_AlbedoTexture = LoadMtl(mtlfilename.c_str());
}
void Model::LoadMtl(const char* filename)
Texture2D* Model::LoadMtl(const char* filename)
{
Msg("Loading MTL file %s...", filename);
Texture2D* pAlbedo = nullptr;
FILE* file = fopen(filename, "r");
if (file == NULL) {
Msg("Model::LoadObj: Impossible to open the file !");
return;
Msg("Model::LoadMtl: Impossible to open the file !");
return nullptr;
}
while (1) {
@@ -575,7 +586,7 @@ void Model::LoadMtl(const char* filename)
fgets(stupidBuffer, 1000, file);
const char* textureFilename = stupidBuffer + 1;
m_AlbedoTexture = g_texturesManager->LoadTexture2D(textureFilename, true);
pAlbedo = g_texturesManager->LoadTexture2D(textureFilename, true);
}
//if (strcmp(lineHeader, "v") == 0) {
@@ -592,6 +603,8 @@ void Model::LoadMtl(const char* filename)
}
fclose(file);
return pAlbedo;
}
void Model::Draw(const glm::mat4& model, SkeletonInstance* instance /*= nullptr*/)
@@ -644,10 +657,10 @@ void Model::Draw(const glm::mat4& model, SkeletonInstance* instance /*= nullptr*
g_shaderSystem->SetUniformMatrix(shader, UNIFORM_MVP_MATRIX, &mvp[0]);
if (!m_AlbedoTexture)
m_AlbedoTexture = g_texturesManager->LoadTexture2D("asdfasdf");
if (!m_data.m_AlbedoTexture)
m_data.m_AlbedoTexture = g_texturesManager->LoadTexture2D("MustBeEvilHackButDontCare");
g_texturesManager->SetTexture(0, m_AlbedoTexture);
g_texturesManager->SetTexture(0, m_data.m_AlbedoTexture);
g_shaderSystem->SetUniformSampler(shader, SAMPLER_ALBEDO, 0);
if (instance)

View File

@@ -15,6 +15,7 @@ class Texture2D;
struct ModelData_t
{
Texture2D* m_AlbedoTexture;
GPUBuffer* vb;
GPUBuffer* ib;
uint32_t vbcount;
@@ -34,7 +35,7 @@ public:
void LoadIqm(const char* filename);
void LoadObj(const char* filename);
void LoadMtl(const char* filename);
Texture2D* LoadMtl(const char* filename);
void Draw(const glm::mat4& model, SkeletonInstance* instance = nullptr);
@@ -69,7 +70,6 @@ private:
std::vector<ModelData_t> m_meshes;
BoundingBox m_boundingBox;
Texture2D* m_AlbedoTexture;
int m_numPoses;
};