reepblue Posted September 17 Share Posted September 17 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 Quote I made this with Leadwerks Game Engine! Cyclone - Vectronic - 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 More sharing options...
Josh Posted September 18 Share Posted September 18 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. Quote 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 More sharing options...
reepblue Posted September 18 Author Share Posted September 18 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. Quote I made this with Leadwerks Game Engine! Cyclone - Vectronic - 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 More sharing options...
Josh Posted September 19 Share Posted September 19 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" } ] } } 1 Quote 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 More sharing options...
reepblue Posted September 19 Author Share Posted September 19 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. Quote I made this with Leadwerks Game Engine! Cyclone - Vectronic - 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 More sharing options...
reepblue Posted Wednesday at 11:00 PM Author Share Posted Wednesday at 11:00 PM 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 Quote I made this with Leadwerks Game Engine! Cyclone - Vectronic - 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 More sharing options...
Josh Posted Thursday at 09:25 PM Share Posted Thursday at 09:25 PM Working on docs: https://www.ultraengine.com/learn/Map_Reload?lang=cpp 2 Quote 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 More sharing options...
reepblue Posted Saturday at 12:34 AM Author Share Posted Saturday at 12:34 AM On 9/21/2023 at 5:25 PM, Josh said: Working on docs: https://www.ultraengine.com/learn/Map_Reload?lang=cpp 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; } Quote I made this with Leadwerks Game Engine! Cyclone - Vectronic - 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 More sharing options...
Recommended Posts
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.