home home

downloads files

forum forum

docs docs

wiki wiki

faq faq

Cube & Cube 2 FORUM


Save/load selected cubes

by RPG on 01/31/2011 20:55, 46 messages, last message: 02/18/2011 23:42, 7852 views, last view: 05/19/2024 02:00

This is idea in editing.
Like copy/paste, but you can save selection on disk and load it later or use in other maps. For example, you create arch/sphere/house and want to save it on disk to use later or use on other map.

These cube "presets" will keep much time when you using geometry of the same type (arches and ladders for example). You could "save" house/ladder/shere from one map and use it in your own map. Very convenient.

Is there any complete solutions?

I think it's possible to create preset library of houses, laggers, spheres, circles, arches and so on like mapmodels, but based on octree geometry.

/loadpreset sphere_4.oct -> put in cursor sphere of radius 4 (just suggestion).

   Board Index    Go to next 20 messagesGo to last 20 messages

#1: ..

by SheeEttin on 01/31/2011 21:13

The only solution right now is to save it in a separate map. (Copy-paste works across maps.)

If you want REAL prefabs, feel free to mod the source to make it possible. (I suggest serializing the cubes you copy into a format you can paste into a CFG.)

reply to this message

#2: ..

by RPG on 01/31/2011 23:04

Yes, I think it is easy, I'm C programmer too, but I don't know cube 2 engine well, 2 megabytes of source is hard to study:). I need to analyze sources before I can modify it.

reply to this message

#3: ..

by RPG on 02/01/2011 00:57

Easier than I thought. I did it!

Here the code I just added in octedit.cpp:

editinfo *preset = NULL;
void savepreset(char *name)
{
vector<uchar> buf;
mpcopy(preset, sel, false);
if(!packeditinfo(preset, buf)) {
conoutf(CON_WARN, "could not get selection"); return;
}
stream *f = openfile(name, "wb");
if(!f) { conoutf(CON_WARN, "could not write preset to %s", name); return; }
f->write(buf.getbuf(), buf.length());
delete f;
conoutf("wrote preset file %s", name);
return;
}
void loadpreset(char *name)
{
int outlen = 0;
uchar *outbuf = (uchar*)loadfile(name, &outlen);
ucharbuf buf(outbuf, outlen);
unpackeditinfo(preset, buf);
mppaste(preset, sel, false);
delete[] outbuf;
return;
}
COMMAND(savepreset, "s");
COMMAND(loadpreset, "s");


Files may be also gzipped.
Now we can collect library of mapmodels in native octree format:)

reply to this message

#4: Re: ..

by |ice|sub-zero|L on 02/01/2011 01:04, refers to #3

Sweet, more useful stuff. XD

reply to this message

#5: ..

by RPG on 02/01/2011 12:46

Screenshot:
http://ompldr.org/vNzhyMQ (save)
http://ompldr.org/vNzhyMg (load)

Code:

void savepreset(char *name)
{
vector<uchar> outbuf;
mpcopy(localedit, sel, true);
if(!packeditinfo(localedit, outbuf)) {
conoutf(CON_WARN, "could not get selection"); return;
}
stream *f = opengzfile(name, "wb");
if(!f) { conoutf(CON_WARN, "could not write preset to %s", name); return; }
int inlen = outbuf.length();
f->write(&inlen, 4);
f->write(outbuf.getbuf(), inlen);
delete f;
conoutf("wrote preset file %s", name);
return;
}
void loadpreset(char *name)
{
stream *f = opengzfile(name, "rb");
if(!f) { conoutf(CON_WARN, "could not load preset %s", name); return; }
int outsize = 0;
f->read(&outsize, 4);
conoutf("%d", outsize);
uchar *inbuf = new uchar[outsize+1];
f->read(inbuf, outsize);
ucharbuf buf(inbuf, outsize);
unpackeditinfo(localedit, buf);
mppaste(localedit, sel, false);
delete[] inbuf;
delete f;
return;
}
COMMAND(savepreset, "s");
COMMAND(loadpreset, "s");

reply to this message

#6: ..

by Osbios on 02/01/2011 13:56

Nice.

Maybe you also want to put

if (noedit(false, true)) return;

at the beginning of each function.

reply to this message

#7: ..

by RPG on 02/01/2011 16:00

if (noedit(false, true)) return;

What does it mean? false, true... maybe:)

reply to this message

#8: ..

by Osbios on 02/01/2011 16:36

The function noedit test if you are in edit mode.

The first value decides if the selection can be outside of your view.
Set it to false so you don\'t edit your selection by accident if you forgot about it, e.g. if you want to edit something later without selecting it explicit and the old selection is still active.

The second value just enables error messages.

The return value gives you the \"its ok to edit\" or \"no no\".

reply to this message

#9: ..

by RPG on 02/01/2011 18:26

I hope to see it in the next release.
Next step - adding presets in menu like mapmodels.

reply to this message

#10: Re: ..

by SheeEttin on 02/01/2011 20:38, refers to #9

May I also suggest a variable to define where these prefabs are stored, so we don't have them cluttering up packages/base? ;)

Also, I'm curious to know why you're delete-ing things that haven't been new'd.

reply to this message

#11: ..

by Razgriz on 02/01/2011 20:42

"could no load preset hoouse"

i guess your fingers are slippery :P

reply to this message

#12: ..

by RPG on 02/01/2011 21:58, refers to #11

> May I also suggest a variable to define where these prefabs are stored, so we don't have them cluttering up packages/base? ;)
I think "packades/presets" will be enough.
packades/presets/ladders
packades/presets/arches
packades/presets/buildings
packades/presets/etc...

I would be very grateful if someone will make a set of primitives such as circles, cylinders, spheres, arches.

> Also, I'm curious to know why you're delete-ing things that haven't been new'd.
What are you talking about?

> i guess your fingers are slippery :P
It was a misprint :D

reply to this message

#13: Re: ..

by SheeEttin on 02/01/2011 22:48, refers to #12

> stream *f;
but:
> delete f;

Unless I'm missing something really obvious.

As for your primitives:
http://quadropolis.us/node/2058
http://quadropolis.us/node/2133
They'd just need to be broken up. :)

reply to this message

#14: ..

by RPG on 02/01/2011 23:23

> > stream *f;
> but:
> > delete f;
>
> Unless I'm missing something really obvious.
Taken from original cube source. I think that's right.

Done:
http://ompldr.org/vNzkydA

showpresetsshot = [ guibar; guiimage (concatword "packages/presets/" (if (> $numargs 0) [result $arg1] [result (at $guirollovername 0)]) ".jpg") $guirolloveraction 4 1 "data/cube.png"]

newgui presets [
guilist [
guilist [
loopfiles f packages/presets pgz [
guibutton $f (concat loadpreset $f) "cube"
]
]
showpresetsshot
]
]
editbind "F7" [if (cleargui 1) [] [showgui presets]]

reply to this message

#15: Re: ..

by suicizer01 on 02/01/2011 23:54, refers to #14

0.0! Very interresting! I really hope it makes the next release, so not only people who map and also program take profit out of it, but also average knowledged mappers.

reply to this message

#16: ..

by RPG on 02/02/2011 16:12

My code still not working as I want. When I try to save/load file only by name (house.pgz for example) - all right. When I try to load it from packades/presets - "could not load preset".
I tried to use "findfile" function - useless. Wheni try to load file from any other folder (except "loadpreset house") - fail.

How to load files from packade folder correctly?
The source code is poorly documented:(

And is there any way to post sources (like patches on sourceforge)? Or devs not take someone else's code?

reply to this message

#17: Re: ..

by tempest on 02/02/2011 17:00, refers to #16

I think you should load presets/blah, not packages/presets/blah.

reply to this message

#18: ..

by RPG on 02/02/2011 17:21

opengzfile("presets/sphere_1.pgz"), "rb");//not working

opengzfile("sphere_1.pgz"), "rb");//working, because i have sphere_1.pgz in ~/.sauerbraten/packades directory

reply to this message

#19: ..

by RPG on 02/02/2011 17:42

I think engine doesn't load file from "packades" in game, but loads files from "packades" in home directory.

reply to this message

#20: Re: ..

by tempest on 02/02/2011 18:31, refers to #19

You'll have to do something like this:
defformatstring(tmppath)("packages/%s.pgz", ppath);
path(tmppath);
opengzfile(tmppath, "rb");

That should work.

reply to this message

   Board Index    Go to next 20 messagesGo to last 20 messages


Unvalidated accounts can only reply to the 'Permanent Threads' section!


content by Aardappel & eihrul © 2001-2024
website by SleepwalkR © 2001-2024
54040815 visitors requested 71821957 pages
page created in 0.091 seconds using 9 queries
hosted by Boost Digital