Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
fix a strange bug about update
Browse files Browse the repository at this point in the history
  • Loading branch information
NeilKleistGao committed Oct 30, 2021
1 parent c6a311c commit fcf4c95
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 21 deletions.
6 changes: 3 additions & 3 deletions kernel/components/sprite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ namespace ngind::components {

Sprite::Sprite()
: RendererComponent(),
_command(nullptr), _quad(nullptr),
_texture(nullptr), _lb(), _rt() {
_command(nullptr), _quad(nullptr),
_texture(nullptr), _lb(), _rt() {
}

Sprite::~Sprite() {
Expand Down Expand Up @@ -100,7 +100,7 @@ void Sprite::draw() {
0.0f, 0.0f, static_cast<float>(_lb.x) / texture_size.x, static_cast<float>(_rt.y) / texture_size.y, // Bottom Left
0.0f, _rt.y - _lb.y, static_cast<float>(_lb.x) / texture_size.x, static_cast<float>(_lb.y) / texture_size.y // Top Left
}
);
);
_quad->addReference();
_command = memory::MemoryPool::getInstance()
->create<rendering::QuadRenderingCommand>(_quad, (*_texture)->getTextureID());
Expand Down
9 changes: 7 additions & 2 deletions kernel/components/state_machine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ _update_function(script::LuaState::getInstance()->getState()) {

StateMachine::~StateMachine() {
halt();
script::LuaState::getInstance()->destroyStateMachineInstance(_instance);
}

void StateMachine::init(const typename resources::ConfigResource::JsonObject& data) {
Expand Down Expand Up @@ -91,15 +90,21 @@ StateMachine* StateMachine::create(const typename resources::ConfigResource::Jso
}

void StateMachine::halt() {
if (_instance.isNil()) {
return;
}

luabridge::LuaRef state_exit = _instance["exit"];
if (!state_exit.isNil()) {
state_exit();
state_exit(_instance);
}

auto instance = script::Observer::getInstance();
for (const auto& [name, _] : _subscribe) {
instance->cancel(this, name);
}

script::LuaState::getInstance()->destroyStateMachineInstance(_instance);
}

void StateMachine::update(const float& dlt) {
Expand Down
2 changes: 0 additions & 2 deletions kernel/log/logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

#include "logger.h"

#include <ctime>

namespace ngind::log {
void Logger::log(const std::string& msg) {
std::string format_msg;
Expand Down
6 changes: 4 additions & 2 deletions kernel/objects/object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void Object::removeChild(Object* child) {
for (auto it = _children.begin(); it != _children.end(); ++it) {
if (it->second == child) {
flag = true;
_children.erase(it);
it->second = nullptr;
break;
}
}
Expand Down Expand Up @@ -99,7 +99,9 @@ void Object::update(const float& delta) {
}

for (auto child : this->_children) {
child.second->update(delta);
if (child.second) {
child.second->update(delta);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions kernel/objects/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class Object : public memory::AutoCollectionObject, public UpdatableObject {
virtual void addChild(const std::string& name, EntityObject* object);

/**
* Remove a reference of a child. If child is not found, nothing
* Remove a reference of a child. If child is not found, nothing will be done
* @param name: the name of child
*/
void removeChild(Object* child);
virtual void removeChild(Object* child);

/**
* Remove all children by given name.
Expand Down
11 changes: 11 additions & 0 deletions kernel/objects/world.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,15 @@ void World::unregisterEntity(int id) {
}
}

void World::removeChild(Object* child) {
for (auto it = _all_children.begin(); it != _all_children.end(); ++it) {
if (it->second == child) {
_all_children.erase(it);
break;
}
}

Object::removeChild(child);
}

} // namespace ngind::objects
2 changes: 2 additions & 0 deletions kernel/objects/world.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class World : public Object {
* Load children objects using config file
*/
void loadObjects();

void removeChild(Object* child) override;
private:
/**
* The name of this world
Expand Down
2 changes: 0 additions & 2 deletions kernel/rendering/renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "renderer.h"
#include "camera.h"
#include "log/logger_factory.h"
#include "adaptor.h"

namespace ngind::rendering {
Renderer* Renderer::_instance = nullptr;
Expand Down Expand Up @@ -100,7 +99,6 @@ void Renderer::createWindow(int screen_width,
glEnable(GL_BLEND);
setBlendFactor(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_MULTISAMPLE);
Adaptor::getInstance()->setWindowSize({screen_width, screen_height});
Camera::getInstance()->init({resolution_width / 2.0f, resolution_height / 2.0f},
resolution_width, resolution_height);
}
Expand Down
7 changes: 1 addition & 6 deletions kernel/rendering/window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,8 @@ void Window::setFullScreen(const bool& is_full) {
if (is_full) {
glfwSetWindowMonitor(this->_window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);

#ifdef PLATFORM_WINDOWS
auto scale = getContentScale();
Adaptor::getInstance()->setWindowSize({ mode->width, mode->height });
#else
auto scale = getContentScale();
Adaptor::getInstance()->setWindowSize({ mode->width * scale.first, mode->height * scale.second });
#endif
Adaptor::getInstance()->setWindowSize({mode->width * scale.first, mode->height * scale.second});
}
else {
glfwSetWindowMonitor(this->_window, nullptr, 0, 0, _width, _height, 0);
Expand Down
2 changes: 0 additions & 2 deletions kernel/ui/kd_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

#include "kd_tree.h"

#include <algorithm>

namespace ngind::ui {
KDTree::KDTree() : _root(new KDNode()) {
}
Expand Down

0 comments on commit fcf4c95

Please sign in to comment.