Medek's ramdom stuff

It's just stuff

What’s been happening

So it’s been awhile (a really long while) since I posted anything about anything. Firstly, yeah I’ve been dicking around with the iphone sdk and stuff like that. I really don’t like Objective C though so don’t know if I’ll keep playing with it.

Another thing is I’ve taken a step away from game development for awhile (I still do little things but Deimos isn’t getting a lot of attention right now). This is mainly down to school and the fact that I get extremely distracted by Deimos (which I’m trying to avoid).

What I am currently working on is an NES emulator, it’s still in the early stages; the cpu is done (official instruction set and a handful of undocumented instructions). Probably be a while before I have screenies to show off. One of the good things about writing this emulator is I’m also learning 6502 assembly and the internal workings of the NES which is fun. Now this is a kinda on and off type deal, it’s just something I do when I have time.

Peace Out.


Enter the iTouch

So I finally got around to getting an iTouch, and I jailbroke it within 2 hours of having it, and now I have a choice; Do I learn ObjC or figure out how to make glue code so I can keep coding in Straight C/++. I’ll probably end up doing both, but right now I am going through the hell of installing iphone-dev again, even though it’s a similar setup to pspsdk/toolchain it’s just hell. After I finally get it set up I am totally rsyncing it.

Oh, I also started school again so now I have an excuse for infrequent posting πŸ˜‰

Peace Out.

Shits gone down.

No, not in a bad way. I got a gig writing some network type software for a company. I can’t really say more than that. Pretty much all game related devving has stopped. When I get time I plan on writing a little something about BSD Sockets, mainly the pitfalls(I’ve had a few).

Also I start back at school on the 3rd so shit is gonna get crazy. That’s about it.

Peace Out.

The marine meets the PSP

So, I’ve been playing with my PSP, and decided to use MD5meshes and MD5anims for character models. The main reason is I wanted to see if the PSP can handle them. See the PSP does support bone matrices BUT not indexed ones. Which means you gotta cut up the model yourself and get everything right before passing to the GU. Also the PSP GU when passing number of weights it’s static and Md5 the weight count changes.

So yeah process everything on the CPU in terms of vertex positions and stuff. I really should rewrite my math functions to use VPU…but pic πŸ™‚

OMG I can't move!!

OMG I can't move!!

One last thing. Be sure to check out #elysian_shadows@Freenode and Elysian Shadows there is a lot of cool shit going on.

Peace Out.

Fucking Youtube

So Get this Falco aka GyroVorbis uploaded some new vids, but cause of youtube being an ass they blocked the 3rd part for his use of the song “Love Shack”.

This kind of copyright bullshit is getting worse, and it pisses me off that people get their shit blocked and deleted over using a song. He was using it under fair use.
Copyright Act 107:

Notwithstanding the provisions of sections 106 and 106A, the fair use of a copyrighted work, including such use by reproduction in copies or phonorecords or by any other means specified by that section, for purposes such as criticism, comment, news reporting, teaching (including multiple copies for classroom use), scholarship, or research, is not an infringement of copyright. In determining whether the use made of a work in any particular case is a fair use the factors to be considered shall include β€”

(1) the purpose and character of the use, including whether such use is of a commercial nature or is for nonprofit educational purposes;

(2) the nature of the copyrighted work;

(3) the amount and substantiality of the portion used in relation to the copyrighted work as a whole; and

(4) the effect of the use upon the potential market for or value of the copyrighted work.

The fact that a work is unpublished shall not itself bar a finding of fair use if such finding is made upon consideration of all the above factors.

Now he was using it for nonprofit uses, and you could say educational since the video has education segments. He only used a segment of the song, and if anything having that in the video would increase market share for that song that has long since dropped out of public scope.

So I have two things to say, one: What the fuck is wrong with youtube’s legal department? And two fuck you youtube.

Falco had this to say:

And I’m COMPLETELY against Youtubeο»Ώ on this one. It’s called FAIR use for a reason. They haven’t lost a single court case to the RIAA–there was no reason for them to start taking it in the ass from the RIAA. Youtube has Google behind them, and Google always claims to support and protect e-freedom from the bullshit ways of sensory and unlawful threats from organizations such as the RIAA. If Microsoft or some other non-Google corporation did this, you guys would all be freaking out and yelling for revolution.

Peace out.


I’m back.

That is all πŸ˜‰

No more devving

OK so this whole thing is frozen till around late June early July. I have over a years worth of work to complete in 3 months(I was devving instead of doing school work).

It really sucks since I was about to write in per pixel lighting for my engine, so that you didn’t get blocky light maps from per vertex. I also was playing around with terrain generation from heightmaps, but All that will have to stop for a bit 😦

Here is some screenies from what I have(minus texture mapping)



more lighting

more lighting

heightmap from wiki :)

heightmap from wiki πŸ™‚

well cya in 3 months I hope…

Lua code injection

So remember when I was talking about a hot patching system for lua, which allows you to execute code in a running thread semi-permanently. Well I finished it, I didn’t get to do the way I had planned and go and patch Lua’s opcodes directly (it’s cool). Instead I added some “injection” routines to my ScriptManager and thread class. Oh if your wondering why injection is in quotation marks, its because its not real injection. Its Fake injection or pseudo injection.

First things first you need somewhere to store and handle your code β€œsnippets”, As I said I used my ScriptManager and thread class. The ScriptManager handles the actual group running (since it holds all threads) and the thread class is where the code is actually stored.

I’ve said it once, I’ll say it again. I’m Lazy this is why I don’t use my own data structures and why reinvent the wheel. So I added the stuff to my thread class.

int AddInjection(std::string code);
int RemoveInjection(int index);//only index not really smart to overload
int PrintInjectionIndexes();//so you can find you code and remove
int RunInjections(); //duh
	std::vector<std::string code> m_injections;

Yeah. So what if I use STL. And in the ScriptManager there is one function needed GlobalRunInjections(). The first few functions are pretty simple just adding and removing elements from m_injections. EchoInjectionIndexes is just too print out console info.

int Thread::EchoInjectionIndexes()
	for(int i = 0; i < m_injections.size(); i++)
		//I made my echo mirror printf for ease
		glConsole::GetSingleton().Echo(β€œ%d - %s\n”, i, m_injections&#91;i&#93;.c_str());
	return 0;

<i>RunInjections</i> this is what your after(well part of it). This is where all the code gets run for a particular thread.

int RunInjections()
	for(int i = 0; i < m_injections.size(); i++)
		//L is the thread
		luaL_dostring(L, m_injections&#91;i&#93;.c_str());
	return 0;

OK the last piece of the puzzle. The new and improved yield function πŸ™‚
&#91;source language="C"&#93;
int LuaYield(lua_State *L)
	return lua_yield(L, 1);
Just so you know this is <i>RunInjections()</i>:

void ScriptManager::RunInjections(lua_State *L)
	for(int i = 0; i < m_threads.size(); i++)
		if(L == *m_threads&#91;i&#93;)

Hmm…So ScriptManager has a function called RunInjections but thread has a function with the same name. Its not a coincidence πŸ™‚
OK so after all that you’ve learned that you just run the code with luaL_dostring in the yield, well you could run them in the run function where lua_resume is called. It shouldn’t make a difference.
Oh screenie. And before you ask. Yes its the pong again but using the “injection” system to render a purple square OMG.

Fake Injection - the implementation is an illusion

Fake Injection - the implementation is an illusion

Now so you know this is one way of doing it. There are many variants and other completely different methods. If you do implement it differently leave a comment, a URL, whatever to let me and others know. Soon as I can omit code already in the thread(at load time aka the script), then we’ll be cooking with gas πŸ™‚

Peace Out.

Wrapping lua errors and print function

So this is just a real quick post. I wanted to wrap all Lua output to my console so I did. Its pretty simple, although if your still using Lua 5.0 getting errors is different(and I’m guessing obsolete) and I’m going to show you anyways.

Getting errors
Firstly Lua’s 5.0 method. See in 5.0 when an error happens a function called _ALERT is called so you wrap it, well override it.

int LuaError( lua_State *L )
	const char* str = lua_tostring( L, -1 );
	lua_pop(L, 1);
	//send string wherever in my case the console
	return 0;
//now register it to a state
lua_register( L_, "_ALERT", LuaError );

Now when I show you the 5.1 way of doing it, you’ll see just how different it is. In Lua 5.1 they scrapped _ALERT at least it looks that way. Instead if execution doesn’t return 0 you’ve got an error then you just pop it off the stack.

	//same for lua_resume, luaL_dofile, etc
	int ret = luaL_dostring(state, input_str);
	if(ret != 0)
		const char *out = lua_tostring(state, -1);
		lua_pop(state, 1);

Thats it no need to bind a function. Personally I like the 5.1 method. I do see the advantages of having Lua call the function itself, but I prefer Lua’s 5.1 method.

Wrapping the print() function
This one will require you to override the built in print function. Ours will behave the same since I ripped it straight from lbaselib.c πŸ™‚

Its really the only way to change the output. See the built in one use fputs to print to stdout. We don’t want that. So the only thing we’ll be changing is how its managed and where its sent.

int LuaPrint(lua_State *L)
	int nArgs = lua_gettop(L);
	int i;
	lua_getglobal(L, "tostring");
	std::string ret;//this is where we will dump the output
	//make sure you start at 1 *NOT* 0
	for(i = 1; i <= nArgs; i++)
		const char *s;
		lua_pushvalue(L, -1);
		lua_pushvalue(L, i);
		lua_call(L, 1, 1);
		s = lua_tostring(L, -1);
		if(s == NULL)
			return luaL_error(L, LUA_QL("tostring") " must return a string to ", LUA_QL("print"));

		if(i > 1) ret.append("\t");

		lua_pop(L, 1);
	//Send it wherever
	return 0;
	//same as before register it with the state
	lua_register(MainState, "print", LuaPrint );

Now lets test it out πŸ™‚

Yes I know its that same pong test again

Yes I know its that same pong test again

So yeah it works. And if your getting tired of seeing that pong test and are wondering when I’ll show something new, I’m working it. I’m currently getting md5mesh/md5anim files loading and rendering correctly, thats why. Right now they look off(well totally fucked up).

Peace Out.

OK messing with threads

I showed how to set up and run threads. But not how I was able to send code from my (most leet) in game console. Here is the console again for anyone who missed it πŸ™‚

Sending the code is actually really easy, its just one function.

//int luaL_dostring (lua_State *L, const char *str);
int ret = luaL_dostring(SomeThread, input_str);

Falco your secrets out. OH NOEZ!!!11! I’m only guessing that he uses that πŸ™‚

The downside to that is that the code you pass is only executed once, so you can’t inject code into the loop and have it execute every time. I have been looking into a way of doing that hacker style, but no real advances yet. And if your asking “Why would you even want too?” the answer is. Why the hell not? Its cool!

Oh here is a little info on the console itself. There are two levels of execution: Console level and Lua level.
Console level is just commands that you bind for example:

CmdFunctor funcEcho(*this, &App::ConsoleEcho);
//Console::AddCommand(const char *cmd, Functor f, bool args)
Console::GetSingleton().AddCommand("echo", funcEcho, true);

In Lua level the console just sends everything to Lua.

The debug command is NOT bound, it is built into the console because it needs to run checks before it runs through the bound commands. See if it was done by using a bound command you’d be able to enter a thread but not exit since the next time you enter debug Lua would interpret it not the console.

That’s about it for now.

Peace Out.