• 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
slicer4ever

How to...

6 posts in this topic

my problem is described in the generic handle documentation, but i don't know how to implement it.

this is basically what i do, each object is given an local pool of memory, the script can say how big that pool is. what i want to do, is create a struct, or class, with each script, get the size of the class, and tell my object to create a pool of memory for this class to occupy, then the script can request the pool, typecast it to the local class, and modify objects/memory in that pool directly.

it'd look like this:

c++ code:
 
class Obj{
private:
   char *m_Buffer;
public:
   void CreateBuffer(int size){
      m_Buffer = new char[size];
   }
   
   char *GetBuffer(void){ //i tried registering this as an ref object, with the scripthandler add-on.
      return m_Buffer;
   }

   //construct/destructors.
};
as script:
 
class Data{
   int x;
};

void Update(Obj @A){
   Data @D = cast<Data@>(A.GetBuffer());
   print("x: "+D.x);
}

void Initialize(Obj @A){
  A.CreateBuffer(sizeof(Data)); //is there anyway to get the size of an class?
  Data @D = cast<Data@>(A.GetBuffer());
  D.x = 0;
};
anywho, this causes angelscript to crash. any pointers on how to achieve this? Edited by slicer4ever
0

Share this post


Link to post
Share on other sites

I have a few questions :)

 

on which line does it crash? you can use the angelScript debugger to step through code and figure out exactly where it's crashing.

 

As for the sizeof() operator, I'm not (entirely) sure, but why not overload a function in the C++ side like so? 


template <typename T>
unsigned int SizeOf(T *x){
  return sizeof(T);
}


//register the function for different types. I haven't used AS in a while, so I'm 
//not really sure about the parameters :)
ASengine->RegisterGlobalFunction("unsigned int sizeof(int @T)", asFUNCTION(SizeOf<int>), asCALL_CDECL);

ASengine->RegisterGlobalFunction("unsigned int sizeof(float @T)", asFUNCTION(SizeOf<float>), asCALL_CDECL);

//.
//.
//.
//and so on for all other types

0

Share this post


Link to post
Share on other sites

I have a few questions smile.png
 
on which line does it crash? you can use the angelScript debugger to step through code and figure out exactly where it's crashing.

I'll step-through it, and get back to you on this. fairly certain it's:
Data @D = cast<Data@>(A.GetBuffer());
though.
 

As for the sizeof() operator, I'm not (entirely) sure, but why not overload a function in the C++ side like so?


This won't work, as the class is dependent on the script. what i want to achieve is to allow each script to need only the external memory it needs to work. in the past i've built a storage container for this, but it meant doing look-ups to map variables/pointers. i'm hoping to find a way that would allow me to map a point in memory directly to a class.

edit: It's happening with this line:
A.GetBuffer();
i'm registering it like so:
ScriptEngine->RegisterObjectMethod("Obj", "ref GetBuffer()", asMETHOD(Obj, GetBuffer), asCALL_THISCALL);
edit2:
this is the crash dialog i get:
 
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.  This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
line 174: as_callfunc_x86.cpp Edited by slicer4ever
0

Share this post


Link to post
Share on other sites

The memory for the script class is not meant to be allocated manually by the application. The script engine must allocate and initialize the memory. A script class doesn't just contain the members declared by the script, there are also hidden data (object type, ref counter, etc) that the application shouldn't manipulate directly.

 

May I ask why you want to do something like this? Perhaps there is another way.

0

Share this post


Link to post
Share on other sites

The memory for the script class is not meant to be allocated manually by the application. The script engine must allocate and initialize the memory. A script class doesn't just contain the members declared by the script, there are also hidden data (object type, ref counter, etc) that the application shouldn't manipulate directly.
 
May I ask why you want to do something like this? Perhaps there is another way.

thanks for the response Andreas=-)
this is basically what i'm attempting to achieve. my game has a generic "Ability" class, what i'd like to do is use angelscript to manage what an ability does, this means different scripts, have different needs. in the past, i wrote a generic container(essentially a dictionary add-on), that got attached to each instance of the class, and the script could customize that container as it needed. the problem with this approach was doing the look-ups into the container to get the appropriate information the script needs.

I was hoping that their would be a way to directly map memory that the script needs to some class, so that i could store a pointer to the scripts unique class in the c++ ability object.

basically, i want to create an instance of a class(this class is unique to each script), attach it to the ability object, and then when the ability is passed to a generic "update" function in the script, it can pull the custom class pointer from the ability object, and i don't have to do any ugly look-ups to continue working/evaluating what an ability is doing.

i think it'd look like this in angelscript:
 
class Data{
   int y;
};

void Initialize(Ablity @Ab){
  Data @x = Data();
  Ab.SetDataObject(x);
};

void Update(Ability @Ab){
  Data @x = @Ab.GetDataObject();
  x.y = 100;
};
obviously not exact, but it's what i'd like to achieve. (essentially script creates class, hands it to the engine to store, and then pulls it out as it needs it. but the engine has zero idea what the class looks like.) I'm fairly certain the generic handler can achieve this, i just don't know how to register my engine to support this setup.


edit:

I've been working on this a bit more, and think i almost have it. I switched my c++ script to hold a pointer to the CScriptHandle object, like so:


class Obj{
private:
   CScriptHandle *m_Handle;
public
   void SetScriptHandle(CScriptHandle *Handle){
      m_Handle = Handle;
   }

   CScriptHandle *GetScriptHandle(void){
      return m_Handle;
   }
};

//Registered like so:
ScriptEngine->RegisterObjectMethod("Obj", "void SetScriptHandle(ref &in)", asMETHOD(Obj, SetScriptHandle), asCALL_THISCALL);
ScriptEngine->RegisterObjectMethod("Obj", "ref &GetScriptHandle()", asMETHOD(Obj, GetScriptHandle), asCALL_THISCALL);
	
I then use it like so:

class Data{
   int x;
};

void Func(Obj @A){
  Data @x = Data();
  x.x = 0;
  A.SetScriptHandle(x);
  A.GetScriptHandle();
};
the above code sets the script handle into the function correctly, and has an appropiate ref object inside the CScriptHandle class. but when i call GetScriptHandle, the CScriptHandle class suddenly no longer has it's ref object. i'm assuming angelscript is releasing x from the ref object, but i have no idea how to keep it in the engine. Edited by slicer4ever
0

Share this post


Link to post
Share on other sites

The CScriptHandle is meant to be used as a value type, so you should preferably store the CScriptHandle member by value rather than by pointer. Like this:

 

class Obj{
  private:
    CScriptHandle m_Handle;
  public
    void SetScriptHandle(CScriptHandle &Handle){
      m_Handle = Handle;
    }

    CScriptHandle &GetScriptHandle(void){
      return m_Handle;
    }
};

//Registered like so:
ScriptEngine->RegisterObjectMethod("Obj", "void SetScriptHandle(const ref &in)", asMETHOD(Obj, SetScriptHandle), asCALL_THISCALL);
ScriptEngine->RegisterObjectMethod("Obj", "ref &GetScriptHandle()", asMETHOD(Obj, GetScriptHandle), asCALL_THISCALL);
 

 

In fact, you can expose the m_handle member directly as an object property, without the need for the Setter and Getter methods if you'd like:

 

ScriptEngine->RegistetObjectProperty("Obj", "ref @m_handle", asOFFSET(Obj, m_handle));

 

That would allow the script to manipulate it directly:

 

// AngelScript
class Data{
  int x;
};

void Func(Obj @A){
  Data @x = Data();
  x.x = 0;
  @A.m_handle = x;
  @x = cast<Data>(A.m_handle);
};

 

Regards,

Andreas

1

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