Jump to content

World::Save spits out empty file.


reepblue
 Share

Recommended Posts

Note: Scene::Save() works fine but doesn't copy over component data. 

The current map doesn't load any components in this test, but it should be worth testing.

#include "UltraEngine.h"
using namespace UltraEngine;

void main(const char* args, const int argc)
{
    //Get the displays
    auto displays = GetDisplays();

    //Create a window
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_TITLEBAR | WINDOW_CENTER);

    //Create a framebuffer
    auto framebuffer = CreateFramebuffer(window);

    //Create a world
    auto world = CreateWorld();

    //Load a scene
    auto scene = LoadMap(world, "Maps/savetest.ultra");

    //Main loop
    while (!window->Closed() and !window->KeyHit(KEY_ESCAPE))
    {
        // Save 
        if (window->KeyHit(KEY_F5))
        {
            world->Save("save.ultra", SAVE_DEFAULT);
        }

        //Load
        if (window->KeyHit(KEY_F6))
        {
            scene = NULL;
            scene = LoadMap(world, "save.ultra");
        }

        //Update world
        world->Update();

        //Render world
        world->Render(framebuffer, true);
    }
}

 

savetest.zip

I made this with Leadwerks Game Engine!

CycloneVectronic - Darkness Awaits Template - Rolly: The Rollable Ball That Rolls Too Much

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

This method just creates a scene object and adds the world entities to it. However, the functionality to add all entities into a list of weak pointers was never added! The fastest fix is for me to just remove this method and the user can create a scene and add entities themselves.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I hope this will be demonstrated in the documentation. I was under the impression we would have "snapshot" saves by default with the world/scene::Save() function. 

It probably only worked with Lua components, but I'm looking forward to an example.

I made this with Leadwerks Game Engine!

CycloneVectronic - Darkness Awaits Template - Rolly: The Rollable Ball That Rolls Too Much

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Yeah, that's the idea. This appears to be working:

    auto p = CreatePivot(NULL);
    p->AddComponent<Mover>();

    auto map = std::make_shared<Scene>();
    map->AddEntity(p);

    map->Save("Maps/out.ultra");

Here is the output:
 

{
	"scene": {
		"base": [],
		"entities": [
			{
				"castShadows": false,
				"collisionType": 0,
				"extras": {
					"components": {
						"Mover": {
							"globalcoords": false,
							"movementspeed": [
								0,
								0,
								0
							],
							"rotationspeed": [
								0,
								0,
								0
							]
						}
					}
				},
				"pickMode": 0,
				"reflection": true,
				"uuid": "ffe028a9-4abe-49de-ba7b-30c2373cf196"
			}
		]
	}
}

 

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Ok, so can just for loop all the entities within the world, and then add it to the scene? I'll give it a try and play around with it. My goal is to have Half Life 2 like save/load states almost transparent to the end user.

Might want to do this for every save call since things like bullets or instanced objects can spawn at any time.

I made this with Leadwerks Game Engine!

CycloneVectronic - Darkness Awaits Template - Rolly: The Rollable Ball That Rolls Too Much

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Regarding components. they don't seem to get updated upon a reload and I have no idea why. This save file has the Mover and a CameraControls component defined in the map file but upon a reload, it's like the components aren't actually being attached for some reason. Does the editor do something different? 

 

quicksave.zip

I made this with Leadwerks Game Engine!

CycloneVectronic - Darkness Awaits Template - Rolly: The Rollable Ball That Rolls Too Much

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

On 9/21/2023 at 5:25 PM, Josh said:

While this example works, it's not working in the way needed for game saves. The reload function throws an exception when trying to read a file and you get a bufferstream overflow with the example below. Also, since Reload doesn't create anything, would I need to load the map file before the save file? If so, what's the best way to know way to know what save file goes to which map?

#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 scene
    auto scene = LoadMap(world, "Maps/savetest.ultra");

    //Save the starting scene to memory
    shared_ptr<BufferStream> stream = NULL;
    shared_ptr<BufferStream> binstream = NULL;

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        if (window->KeyHit(KEY_F5))
        {
            Print("SAVE");
            if (stream) stream = NULL;
            if (binstream) binstream = NULL;
            stream = CreateBufferStream();
            binstream = CreateBufferStream();
            scene->Save(stream, binstream);
        }

        //Reload the starting scene when space key is pressed
        if (window->KeyHit(KEY_F6))
        {
            if (stream and binstream)
            {
                stream->Seek(0);
                binstream->Seek(0);
                scene->Reload(stream, binstream);
            }
        }

        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

I made this with Leadwerks Game Engine!

CycloneVectronic - Darkness Awaits Template - Rolly: The Rollable Ball That Rolls Too Much

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...