Jump to content

  • Log In with Google      Sign In   
  • Create Account


Paril101

Member Since 25 Dec 2012
Offline Last Active Sep 09 2014 05:39 AM

Posts I've Made

In Topic: Member function chaining?

26 December 2012 - 03:19 PM

I'm working on a program:

http://planetminecraft.com/project/mschemv

 

In short, it's a schematic viewer - schematics are collections of blocks that can be imported into maps. It may also support worlds in the future, but atm it only works on Schematics.

I am using AngelScript to supply block renderers (the logic which renders the block itself). Some of these renderers get pretty intense in their logic, so it's neat to see how this is going to work out.

 

I planned to allow users to create their own modules for block rendering, as modifications are HUGE in Minecraft. I looked at a -lot- of different scripting engines, and I just happened to come across AngelScript on a whim and decided to try it out. I have not been disappointed in the slightest. I was so close to being set on using Lua.. but it was giving me too much trouble.

 

Basically, my checklist for a scripting engine was something like this:

- Loading external files into groups of modules (in this case I'm using namespaces as pseudo-modules)

- Allow modules to communicate (ie, if somebody makes a new module which includes a very similar block to another module, they can grab the renderer from that module rather than re-writing code for it)

- Compiles into bytecode (I would like to support compiled versions to decrease file sizes)

 

While those are my basic requirements for implementation, I also had a standard in my mind set for how easy the API should be to access, as well as how easy the language is to learn. While the latter -might- be a problem with new programmers, if I have enough samples it shouldn't be a problem.. as for the API, I don't think you could have done a better job at making it clear.

 

If you'd like to follow the progress in-depth, you can follow the source code here:

http://code.google.com/p/mschemv

(Most of the AngelScript stuff is here: http://code.google.com/p/mschemv/source/browse/trunk/MSchemVLib/Scripting/RenderScriptEngine.cpp )

 

It seems to work without any flaws so far. I was able to destroy the engine and it did not throw any errors. I just noticed too while uploading that you generate debug stats on Debug mode.. my god it's amazing.

 

-P


In Topic: Member function chaining?

26 December 2012 - 02:46 PM

Hey.

 

Thanks for the response. I imagine this is exactly like C++ then, with certain optimizations turned off, what will happen is the object will be constructed, then copied to a local variable on the stack, -then- passed by reference to the function. In a way, it's akin to doing this (in C++):

 

void CallFunc(const Box &);

 

Box box = Box(...);

CallFunc(box);

 

I can understand if AngelScript just doesn't have this optimization to pass r-value references that are constructed right during the call. No problem smile.png

 

If I remove asOBJ_NOHANDLE will it just function normally? It may have been when I was experimenting with different flags to get it working.


EDIT: It's the only type I used that on, as it was the first I created during my AngelScript times. All of my other types only have "asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK".


EDIT2: I'm really excited because I -just- finished the first build which now supports AngelScript for defining block renderers. I figure I would show this off since I assume you like seeing things that can be done with your offspring ;)

 

http://i.imgur.com/wSssV.png

 

(Module.as)

namespace Default
{
	// Returns a ModuleInfo which defines this
	// module.
	::ModuleInfo GetInfo()
	{
		return ::ModuleInfo
				(
					"Minecraft Block Renderers",	// Module name (any characters)
					"mcdefaultblocks",				// Module friendly name (lowercase only, no symbols)
					"1.0",							// Module version
					"Paril"							// Module author
				);
	}
	
	// Initializes and creates renderers.
	void Init(::RendererBase &renderer)
	{
		::ITexture terrain = renderer.GetTexture("terrain.png");

		::AddRenderer(77, Default::ButtonRenderer(terrain, ::Point2i(1 * 16, 0 * 16)));
	}
}

 

(ButtonRenderer.as)

namespace Default
{
	class ButtonRenderer : ::IBlockRenderer
	{
		ButtonRenderer(::ITexture texture, const ::Point2i &in pos)
		{
			Texture = texture;
			Position = pos;
		}

		void Render(::RendererBase &renderer, const ::Block &in block, const ::Point3i &in position)
		{
			renderer.Translate(8, 8, 8);

			switch (block.Data & 0x07)
			{
			case 1:
				renderer.Rotate(90, 0, 1, 0);
				break;
			case 2:
				renderer.Rotate(-90, 0, 1, 0);
				break;
			case 3:
				break;
			case 4:
				renderer.Rotate(180, 0, 1, 0);
				break;
			}

			renderer.Translate(-8, -8, -8);

			renderer.Draw(::Box(Texture, ::Point3i(6, 4, (block.Data & 0x08) != 0 ? 1 : 2), ::Point3i(5, 6, 0)).SetAll(::Point2i(Position.X + 5, Position.Y + 6)));
		}

		::ITexture Texture;
		::Point2i Position;
	}
}

 

 

One tiny question though: why do I have to explicitly specify the namespace for "Default::ButtonRenderer" (in Default::Init) when the current namespace already IS Default? Without it, I get an error that ButtonRenderer is not a proper classname. Is it because they are in different files?

 

-P


In Topic: Member function chaining?

26 December 2012 - 11:23 AM

I always use const &in for most of my types as that seems to work. If I try without in I get yelled at because apparently this type doesn't support inout, and out definitely isn't what I want (nor works), and I want to avoid needlessly creating copies by always passing by value.

 

namespace Default
{
	class DefaultRenderer : ::IBlockRenderer
	{
		void Render(const ::Block &in block, const ::Point3i &in position)
		{
			::renderer.Draw(::Box().SetAll(::Point2i(0, 0), ::Colorb(255, 0, 255, 255)));
		}
	}
}

 

 


	r = engine->RegisterObjectType("Box", sizeof(Box), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CK | asOBJ_NOHANDLE); assert(r >= 0);
	r = engine->RegisterObjectBehaviour("Box", asBEHAVE_CONSTRUCT, "void f(int, Point3i, Point3i)", asFUNCTION(ConstructBox3), asCALL_CDECL_OBJLAST); assert(r >= 0);
	r = engine->RegisterObjectBehaviour("Box", asBEHAVE_CONSTRUCT, "void f(int, Point3i)", asFUNCTION(ConstructBox2), asCALL_CDECL_OBJLAST); assert(r >= 0);
	r = engine->RegisterObjectBehaviour("Box", asBEHAVE_CONSTRUCT, "void f(int)", asFUNCTION(ConstructBox1), asCALL_CDECL_OBJLAST); assert(r >= 0);
	r = engine->RegisterObjectBehaviour("Box", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructBox0), asCALL_CDECL_OBJLAST); assert(r >= 0);
	r = engine->RegisterObjectBehaviour("Box", asBEHAVE_CONSTRUCT, "void f(const Box &in)", asFUNCTION(ConstructBoxC), asCALL_CDECL_OBJLAST); assert(r >= 0);
	r = engine->RegisterObjectMethod("Box", "Box &Unwrap(const Point2i &in)", asMETHOD(Box, Unwrap), asCALL_THISCALL); assert(r >= 0);
	r = engine->RegisterObjectMethod("Box", "Box &SetIndex(const int &in, const Point2i &in, const Colorb &in)", asMETHOD(Box, SetIndex), asCALL_THISCALL); assert(r >= 0);
	r = engine->RegisterObjectMethod("Box", "Box &SetRange(const int &in, const int &in, const Point2i &in, const Colorb &in)", asMETHOD(Box, SetRange), asCALL_THISCALL); assert(r >= 0);
	r = engine->RegisterObjectMethod("Box", "Box &SetNorth(const Point2i &in, const Colorb &in)", asMETHOD(Box, SetNorth), asCALL_THISCALL); assert(r >= 0);
	r = engine->RegisterObjectMethod("Box", "Box &SetEast(const Point2i &in, const Colorb &in)", asMETHOD(Box, SetEast), asCALL_THISCALL); assert(r >= 0);
	r = engine->RegisterObjectMethod("Box", "Box &SetSouth(const Point2i &in, const Colorb &in)", asMETHOD(Box, SetSouth), asCALL_THISCALL); assert(r >= 0);
	r = engine->RegisterObjectMethod("Box", "Box &SetWest(const Point2i &in, const Colorb &in)", asMETHOD(Box, SetWest), asCALL_THISCALL); assert(r >= 0);
	r = engine->RegisterObjectMethod("Box", "Box &SetBottom(const Point2i &in, const Colorb &in)", asMETHOD(Box, SetBottom), asCALL_THISCALL); assert(r >= 0);
	r = engine->RegisterObjectMethod("Box", "Box &SetTop(const Point2i &in, const Colorb &in)", asMETHOD(Box, SetTop), asCALL_THISCALL); assert(r >= 0);
	r = engine->RegisterObjectMethod("Box", "Box &SetSides(const Point2i &in, const Colorb &in)", asMETHOD(Box, SetSides), asCALL_THISCALL); assert(r >= 0);
	r = engine->RegisterObjectMethod("Box", "Box &SetAll(const Point2i &in, const Colorb &in)", asMETHOD(Box, SetAll), asCALL_THISCALL); assert(r >= 0);
	r = engine->RegisterObjectMethod("Box", "Box &SetInset(const int &in, const int &in)", asMETHOD(Box, SetInset), asCALL_THISCALL); assert(r >= 0);
	r = engine->RegisterObjectMethod("Box", "Box &SetTopInset(const int &in)", asMETHOD(Box, SetTopInset), asCALL_THISCALL); assert(r >= 0);
	r = engine->RegisterObjectMethod("Box", "Box &SetSidesInset(const int &in)", asMETHOD(Box, SetSidesInset), asCALL_THISCALL); assert(r >= 0);

 

 

Is there anything I'm doing particularly wrong? It all seems to work properly, so I'm just not sure if I'm breaking standards or what.

 

-P


PARTNERS