Jump to content

Dreikblack

Members
  • Posts

    331
  • Joined

  • Last visited

Posts posted by Dreikblack

  1. 1. Create a brush.

    2. Apply a texture  with console commands:

    local texture = LoadTexture("/Materials/Developer/trigger.dds")
                local material = CreateMaterial()
                material:SetTexture(texture)
                local selected = program:GetSelection()
                for n = 1, #selected do
                    local currentBrush = Brush(selected[n].entity)
                    if currentBrush ~= nil then
    		            currentBrush:SetMaterial(material)
                        currentBrush:Build()
                    end           
                end

    3. Save map - material can be seen in .ultra file.

    4, Save map again - material is gone, Brush still have a line in .ultra: "material": 1

  2. Same problem with Brush

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    
    using namespace UltraEngine;
    
    int main(int argc, const char* argv[])
    {
        //Get the displays
        auto displays = GetDisplays();
    
        //Create a window
        auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
    
        //Create a framebuffer
        auto framebuffer = CreateFramebuffer(window);
    
        //Create a world
        auto world = CreateWorld();
    
        //Create a camera    
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.8);
        camera->Move(3, 0, -2);
        camera->SetDebugPhysicsMode(true);
    
        auto unlitMaterial = CreateMaterial();
        auto unlitShader = LoadShaderFamily("Shaders/Unlit.json");
        unlitMaterial->SetShaderFamily(unlitShader);
    
        int width = 2, height = 1, length = 3;
        auto brush = CreateBrush(world);
    
        brush->AddVertex(0, 0, 0); //S
        brush->AddVertex(-width * 0.5, -height * 0.5, length);//NW
        brush->AddVertex(width * 0.5, -height * 0.5, length);//NE
    
        auto face = brush->AddFace();
        face->AddIndice(0);//S
        face->AddIndice(1);//NW
        face->AddIndice(2);//NE
    
        brush->AddVertex(-width * 0.5, height * 0.5, length);//NW h
        brush->AddVertex(width * 0.5, height * 0.5, length);//NE h
    
        face = brush->AddFace();
        face->AddIndice(0);//S
        face->AddIndice(3);//NW h
        face->AddIndice(4);//NE h
    
        face = brush->AddFace();//left
        face->AddIndice(0);
        face->AddIndice(1);
        face->AddIndice(3);
    
        face = brush->AddFace();//"face"
        face->AddIndice(1);
        face->AddIndice(2);
        face->AddIndice(4);
        face->AddIndice(3);
    
        face = brush->AddFace();//right
        face->AddIndice(2);
        face->AddIndice(4);
        face->AddIndice(0);
    
        //Finalize the coneModel
        brush->Build();
    
        world->SetAmbientLight(1);
    
        //auto& mat = unlitMaterial;
        auto mat = CreateMaterial();
        mat->SetTransparent(true);
        brush->SetMaterial(mat);
        //model->SetColor(0.5f, 0.8f, 0, 0.25f);
        brush->SetPosition(0, 0, 0);
    
    
        Vec3 targetPos(-2, 0, 0);
        auto box = CreateBox(world, 0.1f);
        box->SetPosition(targetPos);
        auto mover = box->AddComponent<Mover>();
        mover->movementspeed.x = 0.2;
    
        brush->Turn(0, 90, 0);
    
        //Main loop
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            targetPos = box->GetPosition();
            auto newTargetPos = TransformPoint(targetPos, nullptr, brush);
    
            bool isInside = brush->GetCollider()->IntersectsPoint(newTargetPos);
            if (isInside)
            {
                brush->SetColor(0, 0.5, 0, 0.5);
            }
            else {
                brush->SetColor(0.5, 0.5, 0.5, 0.5);
            }
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  3. After save:

    image.thumb.png.10b7727763f037b7873e4eb250254f4e.png

    After load:

    image.thumb.png.859e2d7cdd7737608981a5499bd45b5d.png

    #include "UltraEngine.h"
    
    using namespace UltraEngine;
    
    int main(int argc, const char* argv[])
    {
        //Get the displays
        auto displays = GetDisplays();
    
        //Create a window
        auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
    
        //Create a world
        auto world = CreateWorld();
    
        //Create a framebuffer
        auto framebuffer = CreateFramebuffer(window);
    
        //Create a camera    
        auto camera = CreateCamera(world);
        camera->SetClearColor(0.125);
        camera->SetPosition(0, 1, -4);
    
        //Create light
        auto light = CreateBoxLight(world);
        light->SetRange(-10, 10);
        light->SetArea(15, 15);
        light->SetRotation(45, 35, 0);
        light->SetColor(2);
    
        //Create the ground
        auto ground = CreateBox(world, 20, 1, 20);
        ground->SetPosition(0, -0.5, 0);
        ground->SetColor(0, 1, 0);
    
        //Create a scene
        auto scene0 = CreateMap();
        scene0->AddEntity(ground);
        scene0->AddEntity(light);
        ground = NULL;
        light = NULL;
    
        auto scene = CreateMap();
        //Add some boxes
        for (int n = 0; n < 2; ++n)
        {
            auto box = CreateBox(world);
            box->SetColor(0, 0, 1);
            box->SetPosition(Random(-5, 5), Random(5, 10), Random(-5, 5));
            box->SetMass(1);
            scene->AddEntity(box);
        }
    
        //Main loop
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            if (window->KeyHit(KEY_A))
            {
                auto box = CreateBox(world);
                box->SetColor(1, 0, 1);
                box->SetPosition(1, 1, 1);
                box->SetMass(1);
                scene->AddEntity(box);
            }
            if (window->KeyHit(KEY_D))
    		{
    			for (auto box : scene->entities)
    			{
                    if (box->As<Model>())
                        scene->RemoveEntity(box);
                    break;
    			}
            }
            if (window->KeyHit(KEY_S))
            {
                //Save the scene to a file
                scene->Save("game.sav");
            }
            //Load the scene when space key is pressed
            if (window->KeyHit(KEY_SPACE))
            {
                scene = LoadMap(world, "game.sav");
            }
    
            world->Update();
            world->Render(framebuffer);
        }
        return 0;
    }

     

  4. Main visible changes in this year so far:

     

    FPS limiter;
    Settings splitted into categories with custom tabber;
    Sounds effect volume setting added. Also for music too but no music in game atm;
    Default button added to settings for resetting;
    Modal dialog appears if window restart needed (for applying new resolution, localization etc.);
    Special hotkeys for weapons added;
    Controls can be now customized in settings. Control list can be scrolled with mouse scroll;
    Some buttons have tooltips now. It shows what to press to customize an action hotkeys for example;

    Camera reworked to have a smooth rotation around a potential target at center of screen instead of 90 degree rotations;
    Camera can be moved now with cursor near window borders;
    Cursor changes a color above units and tiles;
    New in-game menu;
    Fixed drag'n'drop for inventory (was not smooth and could be stuck if the cursor was out of window etc.). Also dragged item is now highlighted;
    Unit bars reworked into new non-interactive custom sprite UI for improving performance;
    Also as sprite were added lines that connect units and their bars;
    Fixed positional sounds;

    Units now uses movement points to resist being pushed by enemies;
    Action points are now being used as movement points for "sprinting", dodging range attacks, push resistance etc.
    Now attacks can be blocked or dodged only from a front
    Two arcs that look like a circle together under units - their colors show unit team and selection state. Front colors into action or movement color if being targeted by a player from front.
    Unit can be rotated by holding Ctrl (by default) into mouse position.
    Super Shotgun added - can shoot from both barrels to do double damage and double push. Also push back a shooter. It's only weapon that require manual reload (no indicator for ammo yet)

     

    • Like 3
  5. #include "UltraEngine.h"
    
    using namespace UltraEngine;
    
    shared_ptr<Window> window;
    shared_ptr<Framebuffer> framebuffer;
    shared_ptr<World> menuWold;
    shared_ptr<Interface> ui;
    shared_ptr<Camera> uiCamera;
    
    shared_ptr<Widget> panel;
    
    void initGui()
    {
        auto default_font = LoadFont("Fonts\\arial.ttf");
        ui = CreateInterface(menuWold, default_font, framebuffer->GetSize());
        ui->SetRenderLayers(2);
        ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);
        uiCamera = CreateCamera(menuWold, PROJECTION_ORTHOGRAPHIC);
        uiCamera->SetPosition((float)framebuffer->GetSize().x * 0.5f, (float)framebuffer->GetSize().y * 0.5f, 0);
        uiCamera->SetRenderLayers(2);
        uiCamera->SetClearMode(CLEAR_DEPTH);
    
        panel = CreatePanel(10, 50, 64, 64, ui->root, PANEL_DEFAULT);
    }
    
    
    int main(int argc, const char* argv[])
    {
        //Get the displays
        auto displays = GetDisplays();
    
        //Create a window
        window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_DEFAULT);
    
        //Create a world
        menuWold = CreateWorld();
        menuWold->RecordStats();
    
        //Create a framebuffer
        framebuffer = CreateFramebuffer(window);
    
        //Create light
        auto light = CreateBoxLight(menuWold);
        light->SetRange(-10, 10);
        light->SetRotation(15, 15, 0);
        light->SetColor(2);
    
        //Create camera
        auto camera = CreateCamera(menuWold);
        camera->SetClearColor(0.125);
        camera->SetPosition(0, 0, -3);
        camera->SetFov(70);
    
        initGui();
    
        //Main loop
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            if (window->KeyHit(KEY_SPACE))
            {
               {
                   auto uiWindow = ui->GetWindow();
                   if (uiWindow)
                       Print("Interface provided a window");
                   else 
                       Print("No window provided");
               }          
            }
            menuWold->Update();
            menuWold->Render(framebuffer, false);
        }
        return 0;
    }

     

  6. Release also have lower fps but difference is not that noticeable.

    "Benchmark" test with stable build:

    Beta branch:

    Example code:

    #include "UltraEngine.h"
    
    using namespace UltraEngine;
    
    shared_ptr<Window> window;
    shared_ptr<Framebuffer> framebuffer;
    shared_ptr<World> menuWold;
    shared_ptr<Interface> ui;
    shared_ptr<Camera> uiCamera;
    
    shared_ptr<Widget> panel;
    shared_ptr<Icon> icon1;
    shared_ptr<Icon> icon2;
    
    bool isFirst = true;
    
    void initGui()
    {
        auto default_font = LoadFont("Fonts\\arial.ttf");
        ui = CreateInterface(menuWold, default_font, framebuffer->GetSize());
        ui->SetRenderLayers(2);
        ui->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);
        uiCamera = CreateCamera(menuWold, PROJECTION_ORTHOGRAPHIC);
        uiCamera->SetPosition((float)framebuffer->GetSize().x * 0.5f, (float)framebuffer->GetSize().y * 0.5f, 0);
        uiCamera->SetRenderLayers(2);
        uiCamera->SetClearMode(CLEAR_DEPTH);
    
        panel = CreatePanel(10, 50, 64, 64, ui->root, PANEL_DEFAULT);
        icon1 = LoadIcon("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Icons/help.svg");
        icon2 = LoadIcon("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Icons/new.svg");
    }
    
    
    int main(int argc, const char* argv[])
    {
        //Get the displays
        auto displays = GetDisplays();
    
        //Create a window
        window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_DEFAULT);
    
        //Create a world
        menuWold = CreateWorld();
        menuWold->RecordStats();
    
        //Create a framebuffer
        framebuffer = CreateFramebuffer(window);
    
        //Create light
        auto light = CreateBoxLight(menuWold);
        light->SetRange(-10, 10);
        light->SetRotation(15, 15, 0);
        light->SetColor(2);
    
        //Create camera
        auto camera = CreateCamera(menuWold);
        camera->SetClearColor(0.125);
        camera->SetPosition(0, 0, -3);
        camera->SetFov(70);
    
        //Main loop
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
            if (window->KeyHit(KEY_SPACE))
            {
                if (!ui) initGui();
                isFirst = !isFirst;
                if (isFirst)
                {
                    panel->SetIcon(icon1);
                }
                else
                {
                    panel->SetIcon(icon2);
                }
                
            }
            window->SetText("FPS: " + String(menuWold->renderstats.framerate));
            menuWold->Update();
            menuWold->Render(framebuffer, false);
        }
        return 0;
    }

     

    • Upvote 1
  7. One crash fixed and 2nd still happens if you comment out one line that i mentioned in first post. Just to make sure you know what i mean i post code it again with commented line

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    
    using namespace UltraEngine;
    
    int main(int argc, const char* argv[])
    {
    
        RegisterComponents();
        auto fiplugin = LoadPlugin("Plugins/FITextureLoader");
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 1280 * displays[0]->scale, 720 * displays[0]->scale, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
        auto framebuffer = CreateFramebuffer(window);
        auto world = CreateWorld();
    
        WString mapname = "Maps/start.ultra";
        auto scene = LoadMap(world, mapname);
    
        //Main loop
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
    
            if (window->KeyDown(KEY_ENTER))
            {
               // world = CreateWorld();
                scene = LoadMap(world, mapname);
            }
            world->Update();
            world->Render(framebuffer);
    
        }
        return 0;
    }

     

  8. Template map.

    If you hit Enter before activating doors SlidingDoor count will be zero but if you do it after triggering a doors a count will be few dozens.

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    
    using namespace UltraEngine;
    
    int main(int argc, const char* argv[])
    {
    
        RegisterComponents();
        auto fiplugin = LoadPlugin("Plugins/FITextureLoader");
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 1280 * displays[0]->scale, 720 * displays[0]->scale, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
        auto framebuffer = CreateFramebuffer(window);
        auto world = CreateWorld();
    
        WString mapname = "Maps/start.ultra";
        auto scene = LoadMap(world, mapname);
    
        std::weak_ptr<SlidingDoor> slidingDoor;
    
        //Main loop
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
    
            if (window->KeyDown(KEY_ENTER)) 
            {
                for (auto& entity : scene->entities)
                {
                    if (entity && entity->GetComponent<SlidingDoor>())
                    {
                        slidingDoor = entity->GetComponent<SlidingDoor>();
                        scene->RemoveEntity(entity);
                        Print(slidingDoor.use_count());
                        break;
                    }
                }
            }
            world->Update();
            world->Render(framebuffer);
    
        }
        return 0;
    }

     

  9. Default start map from template

    Happens after first enter press:

    image.thumb.png.9924bf4480f3c4f3b5c7b2f9abdb6d68.png

    Comment in loop "world = CreateWorld();" to get another render crash (RecordDraw) but it's not consistent and may take several attempts (Andy have this issue i believe):

    image.thumb.png.93acc1bea7b92a7e6af4b803a5cb61e4.png

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    
    using namespace UltraEngine;
    
    int main(int argc, const char* argv[])
    {
    
        RegisterComponents();
        auto fiplugin = LoadPlugin("Plugins/FITextureLoader");
        auto displays = GetDisplays();
        auto window = CreateWindow("Ultra Engine", 0, 0, 1280 * displays[0]->scale, 720 * displays[0]->scale, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
        auto framebuffer = CreateFramebuffer(window);
        auto world = CreateWorld();
    
        WString mapname = "Maps/start.ultra";
        auto scene = LoadMap(world, mapname);
    
        //Main loop
        while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
        {
    
            if (window->KeyDown(KEY_ENTER)) 
            {
                world = CreateWorld();
                scene = LoadMap(world, mapname);
            }
            world->Update();
            world->Render(framebuffer);
    
        }
        return 0;
    }

     

    • Thanks 1
  10. Reproduced it even with one loop in one main.cpp file. Not creating game gui in callback this time. Have no idea what causing an issue now beside switching between worlds which is somehow working in my Quake Tactics project. btw you mentioned that no issue happens with other map - could be a problem related to player controller or something like that?

    #include "UltraEngine.h"
    #include "ComponentSystem.h"
    
    using namespace UltraEngine;
    
    
    shared_ptr<World> gameWorld;
    shared_ptr<Interface> gameUi;
    
    shared_ptr<Camera> uiCamera;
    shared_ptr<Map> gameScene;
    
    shared_ptr<Window> window;
    shared_ptr<Framebuffer> framebuffer;
    
    shared_ptr<Widget> menuPanel;
    bool isMenuOn = false;
    bool isMainMenuOn = true;
    
    bool resumeGameButtonCallback(const Event& ev, shared_ptr<Object> extra)
    {
        menuPanel->SetHidden(true);
        isMenuOn = false;
        return true;
    
    }
    
    bool mainMenuButtonCallback(const Event& ev, shared_ptr<Object> extra)
    {
        isMainMenuOn = true;
        return true;
    }
    
    
    bool newGameButtonCallback(const Event& ev, shared_ptr<Object> extra)
    {
        isMainMenuOn = false;
        return true;
    }
    
    bool exitButtonCallback(const Event& ev, shared_ptr<Object> extra)
    {
        exit(0);
        return true;
    }
    
    void guiInit()
    {
        // Load a font
        auto font = LoadFont("Fonts/arial.ttf");
    
        // Create user interface
        gameUi = CreateInterface(gameWorld, font, framebuffer->GetSize());
        gameUi->SetRenderLayers(2);
        gameUi->root->SetColor(0.0f, 0.0f, 0.0f, 0.0f);
        gameUi->LoadColorScheme("Resources/configs/Style.json");
    
        // Create ui camera
        uiCamera = CreateCamera(gameWorld, PROJECTION_ORTHOGRAPHIC);
        uiCamera->SetPosition(float(framebuffer->GetSize().x) * 0.5f, float(framebuffer->GetSize().y) * 0.5f, 0);
        uiCamera->SetRenderLayers(2);
        uiCamera->SetClearMode(CLEAR_DEPTH);
    
        int menuWidth = 200;
        int menuHeight = 200;
        int indent = 25;
    
        menuPanel = CreatePanel(framebuffer->size.x * 0.5 - menuWidth / 2, framebuffer->size.y * 0.5 - menuHeight / 2, menuWidth, menuHeight, gameUi->root);
        menuPanel->SetColor(0.2, 0.2, 0.2, 1);
        menuPanel->SetLayout(1, 1, 1, 1);
        menuPanel->SetHidden(true);
    
        int buttonWidth = menuWidth - indent * 2;
        int buttonHeight = 50;
        int posIter = 0;
        int buttonY = indent + posIter * (buttonHeight + indent);
        auto resumeButton = CreateButton("Resume", indent, buttonY, buttonWidth, buttonHeight, menuPanel);
        ListenEvent(EVENT_WIDGETACTION, resumeButton, resumeGameButtonCallback);
        posIter = posIter + 1;
        buttonY = indent + posIter * (buttonHeight + indent);
        auto mainMenuButton = CreateButton("Main Menu", indent, buttonY, buttonWidth, buttonHeight, menuPanel);
        ListenEvent(EVENT_WIDGETACTION, mainMenuButton, mainMenuButtonCallback);
    }
    
    int main(int argc, const char* argv[])
    {
        RegisterComponents();
        //Load FreeImage plugin (optional)
        auto fiplugin = LoadPlugin("Plugins/FITextureLoader");
        //Get the displays
        auto displays = GetDisplays();
        //Create a window
        window = CreateWindow("Ultra Engine", 0, 0, 1280 * displays[0]->scale, 720 * displays[0]->scale, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);
        //Create a framebuffer
        framebuffer = CreateFramebuffer(window);
        //Create a world
        auto world = CreateWorld();
    
        //Load a font
        auto font = LoadFont("Fonts/arial.ttf");
    
        //Create user interface
        auto ui = CreateInterface(world, font, framebuffer->GetSize());
        ui->SetRenderLayers(2);
        ui->root->SetColor(0.2f, 0.2f, 0.2f, 1.0f);
        ui->LoadColorScheme("Resources/configs/Style.json");
    
        //Create ui camera
        auto uiCamera = CreateCamera(world, PROJECTION_ORTHOGRAPHIC);
        uiCamera->SetPosition(float(framebuffer->GetSize().x) * 0.5f, float(framebuffer->GetSize().y) * 0.5f, 0);
        uiCamera->SetRenderLayers(2);
        uiCamera->SetClearMode(CLEAR_DEPTH);
    
        auto newGameButton = CreateButton("New game", 200, 125, 200, 50, ui->root);
        ListenEvent(EVENT_WIDGETACTION, newGameButton, newGameButtonCallback);
    
        auto exitButton = CreateButton("Exit", 200, 200, 200, 50, ui->root);
        ListenEvent(EVENT_WIDGETACTION, exitButton, exitButtonCallback);
    
        gameWorld = CreateWorld();
        gameWorld->RecordStats();
        WString mapName = "Maps/start.ultra";
        gameScene = LoadMap(gameWorld, mapName);
        guiInit();
    
        shared_ptr<World> currentWorld = world;
        shared_ptr<Interface> currentUI = ui;
    
        while (window->Closed() == false)
        {
            if (isMainMenuOn) currentWorld = world; else currentWorld = gameWorld;
            if (isMainMenuOn) currentUI = ui; else currentUI = gameUi;
    
            if (window->KeyDown(KEY_ESCAPE) == true)
            {
                menuPanel->SetHidden(false);
                isMenuOn = true;
                window->SetMousePosition(framebuffer->size.x * 0.5, framebuffer->size.y * 0.5);
            }
            while (PeekEvent())
            {
                const Event ev = WaitEvent();
                switch (ev.id)
                {
                case EVENT_WINDOWCLOSE:
                    if (ev.source == window)
                    {
                        exit(0);
                        break;
                    }
                    break;
                default:
                    currentUI->ProcessEvent(ev);
                    break;
                }
            }
            currentWorld->Update();
            currentWorld->Render(framebuffer);
        }
        return 0;
    }

     

    • Confused 1
×
×
  • Create New...