• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
cvet

Clone object

4 posts in this topic

Hello.

It is possible to clone whole object if we don't know its structure in place where we want do it?

Example:

class c1{}

class c2{}

c1@ handle;

void foo()

{

  @handle = c2();

}

void foo2()

{

  c1 a1 = handle; // here we clone only c1 part of whole object

  c1@ a2 = "clone(handle); // but I want clone whole object and get c2 class, not c1

  c2@ a3 = cast<c2>(a2);

}

0

Share this post


Link to post
Share on other sites

How about implementing a clone method in the script class?

 

class c2 : c1
{
  c2 @clone() { c2 c(this); return c; }
}

 

Else you could implement a clone() function in C++, using the CScriptHandle add-on to receive and return variable handles:

 

// Registered with AngelScript using the signature 'ref @clone(ref @)'
CScriptHandle clone(CScriptHandle hndl)
{
   // Get the handle and type of the received object
   void *obj1 = 0;
   hndl.Cast(&obj1, hndl.GetTypeId());
   asIObjectType *type = hndl.GetType();
 
   // Create a copy of the object
   asIScriptEngine *engine = type->GetEngine();
   void *obj2 = engine->CreateScriptObjectCopy(obj1, type);
 
   // Initialize the CScriptHandle that will be returned
   CScriptHandle c();
   c.Set(obj2, type);
 
   // Make sure we release the handles we will not keep. Cast and Set both increment the refCount
   engine->ReleaseScriptObject(obj1, type);
   engine->ReleaseScriptObject(obj2, type);
 
   return c;
}
0

Share this post


Link to post
Share on other sites

First solution is not good, because will be many classes to add clone function to all, and user may forgot about it.

Second solution not works if handle is on base type.

 

I want it use for gui system, where i want clone gui classes to create multiinstance screens.

 

class GUIObject // Base class

{

  GUIObject@ Clone() { return clone(this); } // I want clone whole object in base class

  void Draw() { OnDraw(); }

  void OnDraw() {}

  void Move() { OnMove(); }

  void OnMove() {}

}

 

class UserGUIObject : GUIObject // User can extend objects to store own data and behaviours, override base methods (used for callbacks)

{

  UserGUIObject@ Clone() { UserGUIObject clone(this); return this; } // I want avoid this solution, bacause user can forgot about this implementation

  void OnMove()

  {

  }

}

 

// GUI system to handle interaction

RegisterGUI(UserGUIWindows());

 

GUIObject@[] WindowObjPrototype;

GUIObject@[] WindowObjActive;

void RegisterGUI(GUIObject& obj)

{

  WindowObjPrototype.insertLast(obj);

}

void InitGUI()

{

  WindowObjActive.clear();

  for(uint i = 0; i < WindowObjPrototype.length(); i++)

    WindowObjActive.insertLast(WindowObjPrototype[i].Clone());

}

DrawGUI(GUIObject& obj)

{

  for(uint i = 0; i < WindowObjActive.length(); i++)

    WindowObjActive[i].Draw();

}

MoveGUI(GUIObject& obj)

{

  for(uint i = 0; i < WindowObjActive.length(); i++)

    WindowObjActive[i].Move();

}

0

Share this post


Link to post
Share on other sites

I think i found solution, without CScriptHandle (i do not use this addon).

This works for me fine (tested).

Please check it, maybe i miss some ref count or do it not optimally:

// Bind: void CloneObject(?&in, ?&out)
// Usage: CloneObject(@from, @to);
void CloneObject( void* in, int in_type_id, void* out, int out_type_id )
{
	if( !( in_type_id & asTYPEID_OBJHANDLE ) )
		FAIL( "Invalid in arg, not an handle." );
	if( !( in_type_id & asTYPEID_SCRIPTOBJECT ) )
		FAIL( "Invalid in arg, not an script object." );
	if( !*(void**) in )
		FAIL( "Invalid in arg, handle must be non null." );
	if( !( out_type_id & asTYPEID_OBJHANDLE ) )
		FAIL( "Invalid out arg, not an handle." );
	if( *(void**) out )
		FAIL( "Invalid out arg, handle must be null." );

	in = *(void**) in;
	asIScriptObject* in_obj = (asIScriptObject*) in;
	in_type_id = in_obj->GetTypeId();
	asIScriptEngine* engine = in_obj->GetEngine();

	if( !engine->IsHandleCompatibleWithObject( in, in_type_id, out_type_id ) )
		FAIL( "Handle not compatible with object." );

	*(void**) out = engine->CreateScriptObjectCopy( in, engine->GetObjectTypeById( in_type_id ) );
}
Edited by cvet
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0