Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

140 Neutral

About transformation

  • Rank
  1. hmm, that's what I was afraid of... Anyway, here's the code: FIrst there's the "strip" and "unstrip" templates that take out the extra stuff surrounding a type. So if you call strip<X, true, true, true, true>::type then X will be the X with reference/pointer/const/volatile removed from it. so If X was const int*, the returned type would be just int. unstrip does the opposite. It puts the qualifiers back on. strip and unstrip are implemented in terms of "add_<qualifier>_if" templates and "remove_<qualifier>_if". They add/remove qualifiers only if the first template parameter is true, so: add_reference_if<true, X>::type // would result in X&. remove_reference_f<false, X>::type // would result in X // This is the main replace implementation: template < class C, class X, class Y > struct replace_impl { static const bool CP = boost::is_pointer<C>::value; static const bool CR = boost::is_reference<C>::value; static const bool CC = boost::is_const<C>::value; static const bool CV = boost::is_volatile<C>::value; static const bool XP = boost::is_pointer<X>::value; static const bool XR = boost::is_reference<X>::value; static const bool XC = boost::is_const<X>::value; static const bool XV = boost::is_volatile<X>::value; static const bool YP = boost::is_pointer<Y>::value; static const bool YR = boost::is_reference<Y>::value; static const bool YC = boost::is_const<Y>::value; static const bool YV = boost::is_volatile<Y>::value; typedef typename strip<C, true, true, true, true>::type stripped_c; typedef typename strip<X, true, true, true, true>::type stripped_x; typedef typename strip<Y, true, true, true, true>::type stripped_y; static const bool Same = boost::is_same< stripped_c, stripped_x >::value; typedef typename select<Same, stripped_y, stripped_c>::type stripped_r; typedef typename unstrip<stripped_r, (XP ^ CP) | YP, (XR ^ CR) | YR, (XC ^ CC) | YC, (XV ^ CV) | YV >::type type; }; Then I have the main replace metafunction: template< class C, class X, class Y > struct replace { typedef typename replace_impl<C, X, Y>::type type; }; and various specializations: template< class C, class X, class Y > struct replace<C, X, const Y&> template< class C, class X, class Y > struct replace<C, X, volatile Y&> template< class C, class X, class Y > struct replace<C, X, volatile const Y&> template< class C, class X, class Y, int N > struct replace<C[N], X, Y> template< class C, class X, class Y, int N > struct replace<C[N], X[N], Y> template< class C, class X, class Y, int N, int M > struct replace<C[N], X[N], Y[M]> template< class C, class X, class Y > struct replace< C (*)(), X, Y > template< class C, class X, class Y, class A > struct replace< C (*)(A), X, Y > So, with all the above, the following should produce a true value, but it produces false: boost::is_same<long*, replace<const int*, const int, long>::type>::value
  2. Hello, I'm going through the c++ template metaprogramming book. And I'm kinda stuck on one of the exercises. In chapter 2, the second exercise (2.1). The question asks you to write a metafunction "replace_type<c, x, y>" that replaces all occurances of x with y, inside the type c. C can be an array, can have cv qualifiers (I'm assuming) and it can be a function pointer with at most 1 argument. So anyway, I'm having trouble following my specializations. My question: is there anyway to see which template specialization the compiler instantiates? My current implementation is passing all tests except for one: replace_type< const int*, const int, long > It works on arrays, pointers and references, but it's not catching that one and I need to be able to follow the instatiations. Is it possible? Thanks.
  3. Thanks deffer! That bind stuff really twsited my head around... scottdewald: You could probably do that with one for_each as well: something like: std::for_each( v.begin(), v.end(), ( _1 = bind( &boost::lexical_cast<std::string,int>, var(x)++ ), std::cout << _1 << '\n' ) ); And no need for a functor And plus, I was just doingthis for experimental reasons... learning how to use lambda that's all.
  4. aloha, I'm currently toying with boost.lamda and I'm trying to get something to work which I can't seem to do... First of all, not using lambda, let me show you wnat I'm trying to do: void a( std::string& v ) { static int x = 0; v = boost::lexical_cast(x++); } void b( std::string v ) { std::cout << v << std::endl; } int main() { std::vector<std::string> v(5); std::for_each( v.being, v.end(), a ); std::for_each( v.being, v.end(), b ); } So just assign a string representing a number that is incrememnted each time it is assigned to the objects in the vector of strings. Now with boost.lambda I need to get the "a" function working, but can't seem to do so, so far I've tried the following but keep on getting errors, either they don't compile or the variable x is not incremented. I've defined x as an int in the code // assume for_all is defined as // #define for_all( o, x ) for_each( o.begin(), o.end(), x ) int x = 0; for_all( v, (_1 = lexical_cast<std::string>(_2++)(_1, x) ) ); for_all( v, (_1 = bind( lexical_cast<std::string>(), x++ ) ) ); for_all( v, (_1 = lexical_cast<std::string>(x), (_1 += 1)(x) ) ); for_all( v, (_1 = lexical_cast<std::string>(x), (*_1 += 1)(&x) ) ); for_all( v, (_1 = lexical_cast<std::string>(x), boost::lambda::var(x) += 1 ) ); for_all( v, (_1 = lexical_cast<std::string>(x), bind(x,_1) += 1 ) ); for_all( v, _1 = lexical_cast<std::string(x), bind(std::plus<int>(), x) ); for_all( v, _1 = lexical_cast<std::string>(x++) ); Can anyone help me out? Is something like what I'm trying to do even possible with lambda? Thank you.
  5. transformation

    exception not being caught in catch block.

    woopsy.... i was inheriting privately from std::exception. Everything worked fine after i changed to class cw::exception : public std::exception {}; Sorry :)
  6. hello, ok, so i have a dll and an exe project. I'm calling the function cw::x() from the dll. cw::x() in turn calls function cw::y() which is also part of the library. and finally cw::y() throws a cw::exception object. cw::exception actually inherits from std::exception. note: cw is a namespace, not an object. in the exe, from main i have this: main() { try { cw::x(); } catch( std::exception& e ) { std::cout << e.what() << std::endl; } } But whenever i ran the application, i get an unhandled exception message from windows. you know that "this application has requested the runtime to close it in a weird way" message in my console window. am i missing something?
  7. Yeah, i got it. Thanks for the feedback... I've been looking into some methods of getting a bunch of tiles that are viewable and not being blocked... does anyone know of any existing algos that can do that? I read around and from what i undestand: First get the tiles that intersect with a view cone (any algo for that?) Then, use bresenhams to see which tiles are visible.
  8. hi Zahlman... what do you mean exactly when you say the abstraction is broken? with the getDir()? ok, i think i know what you mean, but the thing is that bots are placed inside the level randomly and with a random direction, so without the getDir, there really is no way to see which direction your bot is facing... Does the getDir give an unfair advantage to a scripter? Is it information that should not be given? oh and why? Anonymous: A what? what's an arc scanner? And how would you go about this in a tile based application where you can only move either left up down or right? Thanks guys.
  9. Hello, I think I should've asked this stuff a long time ago, but anyway... For my finnal year project i've created a bot simulator. The goal of this simulator is to provide a framework for testing out AI implementations. The simulator is 2D and tile based, so nothing too fancy. So the simulator is integrated with lua, and to control a bot, you first create a script that has 3 functions - Init, Update and Shutdown. The init function is called when the environment is initialized and the shutdown when the environment is destroyed. The update method is called once per bot per x seconds. So anyway, I want the functionality provided to make AI development as easy as possible with this thing... problem is I've never done AI development and wouldnt know what kind of functionality is really really needed, so I'm here to ask: As in what kind of funnctions do I need to bind to lua to be more precise. I already have the following: Go() - tells simulator that your bot is moving in the direction you've set SetDir(Dir) - points the bot wherever GetDir() - gets your direction Stop() - stops your bot movement in the direction that its set in Fire() - fires a bullet GetHealth() - return how much health points you have left GetLeftTile() - tells you what tile type is on your left GetRightTile() - tells you what tile type is on your right GetFrontTile() - tells you what tile type is in front of you GetBackTile() - tells you what tile type is behind you So anyway, those are the functions I currently have. The few final caveats are that you can only have 5 active bullets at a time, if you Fire() when after you already have 5 in teh field, Fire() does nothing. Your Update() function is executed every 150 millisecods to be precise, that means you can do a bunch of stuff every 150 millisecs... and each bots script is carried out in turn or creation. Next is that if you Fire() you cannot SetDir() in the same Update call... You can call both, but only one or the other will be executed (The first one the script finds) What I'm asking is will I need a function like GetNumActiveBots() or a function like GetTileAtPos(x, y) or whatever other function to be made available to the lua scripter? I've already created a thread in Your Announcements forum announcing the completion of this software with a download link, but after playing with this thing a lot yesterday, I've realized that I need design opinions before people actually start testing this thing out...
  10. Hey people! I finished this little application I've been working on, it' more or less a copy of GDArena only not 3D but 2D tile based, and it uses lua for the scipting bit... Also, I'm not quite sure of the type of functionality that I'd need to implement to help out with the scripting bit... as in, currently I allow for the getting of the tile types that are around you which let you know if there's a wall in front of you or behind you etc... or a bot or the tile is an empty one etc... I've created a dummy script that I have 8 bots all using at the same time, so the bots are not very smart in this demo. But please do give it a whirl if only to see that all is working well. If you do happen to create some nicer scripts, then please do share :) Download! Everything you need to know should be in the readme.txt (there's also a readme in the "scripts" folder that you need to check before creating your own script). Thanks for any feedback! [edit] Changed download... added msvc++ dependancies just incase. [/edit] [edit] Added sounds and destructable level feature. Also added the ability to fire missiles as well. [/edit] [Edited by - transformation on August 16, 2006 4:13:35 AM]
  11. Thanks MENTAL! that map technique I can do something with... I don't know of any setuserdata function, but it gave me another idea... You can set global vars within a script from lua, so for script1 I can set a global var called BOTID the bot's index within the std::vector of bots i'm storing... lua_State will have it's own script file and it's own BOTID set to a corresponding index.... Thanks.
  12. That update function is in the lua script file... I dont get what you're saying..? I think i need to explain a bit more... You see, say I have 3 bots and 3 scripts. So bot1->script1 etc... Now in C, i need to call each bots Update() function that's within the script. So I need to do soemthing like: int GetHealth( lua_State* s, CBot* bot ) { lua_pushnumber( L, bot->GetHealth() ); return 1; } lua_pushcfunction( s, GetHealth ); lua_setglobal( s, "GetHealth" ); But the problem is that lua_pushcfunction takes a specific function signature that wont allow the above...
  13. Hello, I've been developing an application more or less like gdarean, only it's 2D and not as robust. The problem i'm having is with Lua. There's a CBot object for each bot on the map. Each CBot object has it's own lua state object, since each bot has its own script. In the script, 2 functions are required: Init, Update and Shutdown. Now say in the Update function I have something like: function Update() print( GetHealth() ) end Of course GetHealth() is a function in C and it's exported to the lua environment. THe problem I'm having, is how do I make a seperate GetHealth() function for each bot? int GetHealth( lua_State* s ) { lua_pushnumber( L, iMyBotsHealth ); return 1; } lua_pushcfunction( s, GetHealth ); lua_setglobal( s, "GetHealth" ); Now if I call GetHealth() from inside lua, it'll return the same bot's helth everytime, no matter which bot script is being run... Is there some trick to get around this problem? Have I explained the problem well enough even?
  14. transformation

    vectors and vector space. And projection and clip space.

    Thanks Zipster, that about clears things up for now. I'll be back soo though (probably more "transform" related questions :))
  15. I posted the original thread in the maths forum, one of the posters suggested I'd get a better respose from this forum, so if you guys could go check it out and provide any answers I'd really appreciate it. click Thanks.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!