Warning: Creating default object from empty value in /home/customer/www/code-plan.org/public_html/code-plan.org/wp-content/themes/virtue/themeoptions/inc/class.redux_filesystem.php on line 29

Warning: Cannot modify header information - headers already sent by (output started at /home/customer/www/code-plan.org/public_html/code-plan.org/wp-content/themes/virtue/themeoptions/inc/class.redux_filesystem.php:29) in /home/customer/www/code-plan.org/public_html/code-plan.org/wp-includes/feed-rss2.php on line 8
Rafal Wanowicz https://code-plan.org Wed, 17 Jun 2020 00:48:39 +0000 en-US hourly 1 https://wordpress.org/?v=5.9.3 Sprite Editor https://code-plan.org/sprite-editor/ https://code-plan.org/sprite-editor/#respond Mon, 26 Nov 2018 02:42:55 +0000 https://code-plan.org/?p=475 Continued]]>  

I have finally implemented sprite editor. The sprite sheet can be edit inside the engine and sliced down. Currently there is only manual slicing available, but I am planning to add automatic slicing tool in the future, which will slice down the entire sprite sheet in equally regions..

This addition is improving productivity when creating game as you can do everything from within the engine. When editing the sprite sheet you can select only the sprites you want appear in your animation, They do not have to be selected in order , which can produce very interesting results. There are many more feature on my list, which  I would like to add the the sprite editor, but for now the basic sprite editor will be enough. I will definitely modify it in the near future.

]]>
https://code-plan.org/sprite-editor/feed/ 0
Profiler https://code-plan.org/profiler/ https://code-plan.org/profiler/#respond Mon, 26 Nov 2018 02:24:49 +0000 https://code-plan.org/?p=472 Continued]]> have been adding more and more functionality to my engine and started to see that is my is my engine slowing down. To render or animate scene with 100 sprites in my engine dropped to 30 FPS , which is not very good as previously I was able to run it at 60 FPS. I have decided to add build-in profiler tool, which will be measure the execution time every single function in the game. Although I could use the build-in the Visual Studio profiling tools to find out what is hitting the performance, but I have decided that it would be nice to have my own tool which will be implemented in the engine and used whenever needed. I have implemented the ExecutionTimer class which measure the execution time of the function during its lifetime. This class start execution timer in the constructor and measure it until the object is destroyed.

 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//Measure the time of executing function. The lifetime of the function
struct ExecutionTimer
{
    std::chrono::time_point<std::chrono::steady_clock> start;
    std::chrono::time_point<std::chrono::steady_clock> end;
    std::string function_name;
    std::string file_name;

    const float error_time = 0.01f;
    const float warning_time = 0.005f;

    ExecutionTimer(std::string const& fileName, std::string const& functionName);
    ~ExecutionTimer();
};

ExecutionTimer::ExecutionTimer(std::string const& fileName, std::string const& functionName)
    : start(std::chrono::high_resolution_clock::now())
    , function_name(functionName)
    , file_name(fileName)
{
}

ExecutionTimer::~ExecutionTimer()
{
    end = std::chrono::high_resolution_clock::now();

    //If the function is already in the vector do not add it just modify start and end time if is greater than the current value
    const auto result = std::find_if(ProfilerDataList.begin(), ProfilerDataList.end(),
        [&](const auto& element)
        {
            return (element.function_name == function_name && element.file_name == file_name);
        });

    if (result == ProfilerDataList.end())
    {
        //Not found
        ProfilerDataList.emplace_back(
            ProfilerData{
                file_name,
                function_name,
                start,
                end
            });
    }
}

To have simple access to the class I have decided to add a simple macro which could be put at the beginning of the function and measure its performance.


1
2
3
4
5
6
7
8
//to print only file name without full path
#define __FILENAME__ (strrchr(__FILE__,'\')+1)

#ifdef USE_PROFILER
#define SCOPE_MEMBER() ExecutionTimer(__FILENAME__, __FUNCTION__)
#else
#define SCOPE_MEMBER()
#endif

All of the results are than saved in the vector files and outputted to the HTML report. Below is the report generated by the engine.

]]>
https://code-plan.org/profiler/feed/ 0
New Engine Editor GUI https://code-plan.org/new-editor-gui/ https://code-plan.org/new-editor-gui/#respond Mon, 19 Feb 2018 11:42:53 +0000 https://code-plan.org/?p=454 Continued]]>

Finally I have found suitable GUI library. I have decided to use Dear ImGui library you can find it here.

I have integrated this library into my engine and I think looks much better than with pure WIN32 API. I think this was good decision as I do not have to spent too much time to add new gui controls like button or label or list or even creating new window. This library is very easy to use and I definitely recommend it to anyone. I still need to put much more work in the Editor Gui as is missing a lot of  functionality, but I am very happy with the current result.
Currently you can manipulate all components, selecting and displaying components for specific game object in the scene through the Editor.

I have also added new Mesh Rendering component which handling 3D models. Still need to test it but for now the Engine is handling obj. and fbx models.
]]>
https://code-plan.org/new-editor-gui/feed/ 0
Added Engine Editor https://code-plan.org/added-engine-editor/ https://code-plan.org/added-engine-editor/#respond Mon, 19 Feb 2018 11:19:46 +0000 https://code-plan.org/?p=446 Continued]]>

I have decided to add Engine Editor. Something similar to the one you can find in Unity 3D. Currently my editor has three parts.

1. Tool Window – this window display list of the scene elements.From here new game object can be added to the scene. By selecting specific object we can display all game components it has.
2. Inspector Window – in this window we can see and manipulate all of the components that specific entity has. We will be able to add more or remove component.
3. Project Structure Window – This window displays all of the resources currently available like scenes graphics, models and sounds. From this window we will be able to open new scene, drag and drop graphisc on the Sprite Rendering component and apply it.

I have been searching for the right GUI library which will not impact on the engine performance. After few weeks of searching I have decided to go low level with WIN32 API. You can see the beginning layout of the Engine Editor above. Program everything in the WIN32  API is not difficult, but is tedious and taking longer than usually to add simple GUI element and position it correctly. I am still searching for good free GUI library for C++ and OpenGL. Until I will find something suitable. I will stick with the Windows controls. If you have any suggestions you can post it in the comments below.
]]>
https://code-plan.org/added-engine-editor/feed/ 0
Engine Code Example https://code-plan.org/test/ https://code-plan.org/test/#respond Mon, 19 Feb 2018 00:07:05 +0000 https://code-plan.org/?p=434 Continued]]> Below is the code example of how the new entity can be created. I have snipped Sprite Entity class from my engine. More code examples will be added soon.

 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "Sprite.h"
#include "Utilities.h"
#include "ShaderManager.h"
#include "PlayerBehaviour.h"

Sprite::Sprite()
    : position_(glm::vec3(0.0f, 0.0f, 0.0f))
    , scale_(glm::vec3(1.0f, 1.0f, 1.0f))
{
}

void Sprite::Init(std::string const& file_name, RenderingOrder order, int column_number, int row_number, float pos_x, float pos_y)
{
    SCOPE_MEMBER();
    rendering_order_ = order;
    position_.x = pos_x;
    position_.y = pos_y;
    name_ = file_name;

    AddComponent(new TransformComponentData(position_, scale_, shared_from_this()));
    AddComponent(new SpriteRendererComponentData(
        file_name,
        row_number,
        column_number,
        1,
        1,
        60,
        shared_from_this()
    ));

    AddComponent(new WindowsSoundComponentData("c:\\windows\\media\\Alarm05.wav"));


    if (HasComponent(BEHAVIOUR_COMPONENT))
    {
        GetComponent<BehaviourComponentData>()->behaviour_component->Start();
    }
}

void Sprite::Update(float delta_time) //IEntity
{
        IEntity::Update(delta_time);
    if (HasComponent(BEHAVIOUR_COMPONENT))
    {
        GetComponent<BehaviourComponentData>()->behaviour_component->Update(delta_time);
    }
}

RenderingOrder Sprite::GetRenderingOrder()
{
    return renderingOrder_;
}

this is the example code how we can use this entity inside our game project


1
2
3
4
5
sprite_test = make_shared();
sprite_test->Init("BoneSprite.png", RenderingOrder::RO_FIRST, 5, 1, 100, 20);
sprite_test->GetComponent()->autoAnimate = true;
sprite_test->GetComponent()->updateFrameRate = 15;
EntityManager::GetManager()->registerEntity(sprite_test);

This is the definition of one of the standard entity, which can be used. Although There is also possible to create custom Entity inside the game project and assign wanted components to it.

To separate entity logic and make our project cleaner we can attach behavior script to this entity and put our logic in it. The standard behavior script have to inherit from IBehaviourComponentClass and implement Start() and Update() function. Start Function is called only once per game ,where update is called every frame.

Below is the code snipped from the PlayerBehaviourScript


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once
#include "IBehaviourComponent.h"
#include "IEntity.h"

class PlayerBehaviour : public IBehaviourComponent
{
public:
    PlayerBehaviour() = default;
    PlayerBehaviour(IEntity* entity);
    ~PlayerBehaviour();
   
    //IBehaviourComponent
    void Start();
    void Update();
    void SetOwner(IEntity* entity) { entity_ = entity; }

private:
    IEntity* entity_;
};

//***************************************************************************************
PlayerBehaviour.cpp
//***************************************************************************************

#include "PlayerBehaviour.h"
#include "GLWindow.h"
#include "EntityManager.h"

PlayerBehaviour::PlayerBehaviour(IEntity* entity)
{
    entity_ = entity;
}

PlayerBehaviour::~PlayerBehaviour()
{
    if (entity_)
        delete entity_;
}

//IBehaviourComponent
void PlayerBehaviour::Start()
{
}

void PlayerBehaviour::Update()
{
    if (Cyber::Input::IsMouseButtonPressed(CB_MOUSE_BUTTON_1))
    {
        entity_->GetComponent<TransformComponentData>()->position.x += (1.0f * delta_time);
    }
}

And this is how the Bhaviour script can be assigned to the specific Entity


1
2
3
4
5
6
shared_ptr NewSprite = make_shared();
NewSprite->SetName(name);
// ScriptFactory::GetBehaviourScript(ScriptName);
NewSprite->AddScript(ScriptFactory::GetNewScript(ScriptName));
NewSprite->Init("BoneSprite.png", RenderingOrder::RO_FIRST, 5, 1, 100, 20);
EntityManager::GetManager()->RegisterEntity(NewSprite);

We can get different entity from our script and access its functionality. This make its easy to implement our game logic.

Like above we access Enemy position from PlayerBehaviour script.

]]>
https://code-plan.org/test/feed/ 0