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

justin12343

Members
  • Content count

    184
  • Joined

  • Last visited

Community Reputation

217 Neutral

About justin12343

  • Rank
    Member
  1. Angelscript does not seem to be able to properly call the copy constructor of a simple POD type that is being returned from a registered global function for some reason. When it does call the copy constructor, the this pointer of the new object is null, but the input variable has a valid address from the c++ function. I'm using version 2.31.0 WIP.   The problem seems to be around line 1097 in as_callfunc_x86.cpp: // Copy return value from EAX:EDX lea ecx, retQW mov [ecx], eax mov 4[ecx], edx My C++ code: PointF Instance::GetBodyPos() { PointF pos; if (pBody) { pos.Set( pBody->GetPosition().x*MTP_RATIO, pBody->GetPosition().y*MTP_RATIO); } return pos; //<------------- Crashes on return. pos gets passed in correctly though }
  2. It's running on ARM, ARMv7 on a HTC One M8 to be specific.   Edit: The changes work like a charm! Thanks.
  3. I'm experiencing a crash when calling native functions from script, which are precompiled by the way.   This is the function causing all of the trouble: r = pEngine->RegisterGlobalFunction( "void DrawSprite( int,int,PointF)", asMETHOD(Renderer, DrawSprite), asCALL_THISCALL_ASGLOBAL, pGm->GetRenderer()); assert(r >= 0); PointF is defined like so: class PointF { public: PointF(); PointF( float _x, float _y); PointF( const PointF &other); void Set( float _x, float _y); void SetX(float _x); void SetY(float _y); float GetX(); float GetY(); private: float x, y; }; void ConstructorDefaultPointF( PointF *m); void ConstructorInitPointF( float x, float y, PointF *m); void ConstructorCopyPointF( const PointF &other, PointF *m); void DestructorPointF( PointF *m); //PointF r = pEngine->RegisterObjectType("PointF", sizeof(PointF), asOBJ_VALUE|asOBJ_POD|asGetTypeTraits<PointF>()); assert( r >= 0); r = pEngine->RegisterObjectBehaviour( "PointF", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructorDefaultPointF), asCALL_CDECL_OBJLAST); assert( r >= 0); r = pEngine->RegisterObjectBehaviour( "PointF", asBEHAVE_CONSTRUCT, "void f(float,float)", asFUNCTION(ConstructorInitPointF), asCALL_CDECL_OBJLAST); assert( r >= 0); r = pEngine->RegisterObjectBehaviour( "PointF", asBEHAVE_CONSTRUCT, "void f(const PointF &in)", asFUNCTION(ConstructorCopyPointF), asCALL_CDECL_OBJLAST); assert( r >= 0); r = pEngine->RegisterObjectBehaviour( "PointF", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(DestructorPointF), asCALL_CDECL_OBJLAST); assert( r >= 0); r = pEngine->RegisterObjectMethod( "PointF", "void Set(float,float)", asMETHOD( PointF, Set), asCALL_THISCALL); assert( r >= 0); r = pEngine->RegisterObjectMethod( "PointF", "void SetX(float)", asMETHOD( PointF, SetX), asCALL_THISCALL); assert( r >= 0); r = pEngine->RegisterObjectMethod( "PointF", "void SetY(float)", asMETHOD( PointF, SetY), asCALL_THISCALL); assert( r >= 0); r = pEngine->RegisterObjectMethod( "PointF", "float GetX()", asMETHOD( PointF, GetX), asCALL_THISCALL); assert( r >= 0); r = pEngine->RegisterObjectMethod( "PointF", "float GetY()", asMETHOD( PointF, GetY), asCALL_THISCALL); assert( r >= 0); DrawSprite is only being called once per frame so far and works for the first 2 frames, but then the app crashes here: as_scriptengine.cpp void asCScriptEngine::CallFree(void *obj) const { #ifndef WIP_16BYTE_ALIGN userFree(obj); <----------------- Crashes in the free function of libc #else userFreeAligned(obj); #endif } Upon examining the problem further, addr points to a pointer holding a strange address, like 0x0000c000 or something as_callfunc.cpp // Clean up arguments const asUINT cleanCount = sysFunc->cleanArgs.GetLength(); if( cleanCount ) { args = context->m_regs.stackPointer; // Skip the hidden argument for the return pointer if( descr->DoesReturnOnStack() ) args += AS_PTR_SIZE; // Skip the object pointer if( callConv >= ICC_THISCALL ) args += AS_PTR_SIZE; asSSystemFunctionInterface::SClean *clean = sysFunc->cleanArgs.AddressOf(); for( asUINT n = 0; n < cleanCount; n++, clean++ ) { void **addr = (void**)&args[clean->off]; if( clean->op == 0 ) { if( *addr != 0 ) { engine->CallObjectMethod(*addr, clean->ot->beh.release); *addr = 0; } } else { asASSERT( clean->op == 1 || clean->op == 2 ); asASSERT( *addr ); if( clean->op == 2 ) engine->CallObjectMethod(*addr, clean->ot->beh.destruct); engine->CallFree(*addr); } } } return popSize; }  The app runs fine if DrawSprite is not called though. What could be causing this?
  4.  I've decided to take a second look at this problem since I upgraded to 2.27.1 and there seems to be another issue with compiling. This will mostly be a re-post of what I submitted on the JIT's git repo:   The jit seems to not compile any scripts in version 2.27.1 for me at this point that contain classes. This is the very first script that is compiled in my engine: shared class Base_Object { //========== Constructor / Destructor =========== Base_Object( Object @obj) { @this.object = obj; x = object.x; y = object.y; sprite_index = -1; mask_index = sprite_index; image_index = object.image_index; depth = object.depth; } //=========== Events ============= void Create(){} void Destroy(){} void Alarm1(){} void Alarm2(){} void Alarm3(){} void Alarm4(){} void Alarm5(){} void Alarm6(){} void Alarm7(){} void Alarm8(){} void Alarm9(){} void Alarm10(){} void Alarm11(){} void BeginStep(){} void Step(){} void EndStep(){} void Collision( int objType, int objId, Object @other){} void Key( int key){} void KeyPressed( int key){} void KeyReleased( int key){} void MouseButton( int button){} void MouseButtonPressed( int button){} void MouseButtonReleased( int button){} void JoystickButton( int id, int button){} void JoystickButtonPressed( int id, int button){} void JoystickButtonReleased( int id, int button){} void OutsideRoom(){} void OutsideView(){} void IntersectBoundary(){} void GameStart(){} void GameEnd(){} void RoomStart(){} void RoomEnd(){} void NoMoreLives(){} void NoMoreHealth(){} void AnimationEnd(){} void EndOfPath(){} void Draw(){} //======= Collision ========= bool place_meeting( float mX, float mY, int type) { return object.PlaceMeeting( mX, mY, type); } bool place_meeting_depth( float mX, float mY, int depth, int type) { return object.PlaceMeetingDepth( mX, mY, type, depth); } Base_Object @object_place( float mX, float mY, int type) { Base_Object @base = null; Object @obj = object.ObjectPlace( mX, mY, type); if (@obj != null) @base = cast<Base_Object>(@obj.GetScriptObject()); return base; } bool collision_rectangle( float x1, float y1, float x2, float y2, int type) { return object.CollisionRectangle( x1, y1, x2, y2, type); } //========== Misc =========== uint GetId() { return object.GetId(); } void SetRect( int l, int t, int w, int h) { object.general_rect.left = l; object.general_rect.top = t; object.general_rect.right = l+w; object.general_rect.bottom = t+h; } /*Base_Object@ opAssign(Base_Object_IMP @in) { return @cast<Base_Object>( @in.GetScriptObject()); }*/ //======= Variables ========= Object @object; float x; float y; int sprite_index; int mask_index; int image_index; int depth; } I'm thinking there's problem with classes because it doesn't fail when compiling just a simple function. The assert in the following code section fails because there is a null pointer to scriptData: void asCScriptFunction::JITCompile() { asIJITCompiler *jit = engine->GetJITCompiler(); if( !jit ) return; asASSERT( scriptData ); ........ Even something as simple as this doesn't compile: class test { void t(){} } Note that this will compile: void t(){}; Now with further investigation I found that the function data for "t()" in the virtual function table of asIObjectType is valid (but where ever the module gets it from, it is not). Shouldn't angelscript be calling JITCompile() on the function in the virtual table? I'm still quite unfamiliar of how AS handles class methods, but whatever has changed since version 2.26.3 has broken the JIT.
  5.   I have the jit source files integrated directly into my Visual Studio project so I recompile after updates anyways. I'm not familiar with AngelScript's internals but the problem maybe linked to the object register, since asCContext::GetAddressOfReturnValue() returns a null pointer from it. I've submitted a issue on the Git repository.
  6. Nevermind, the code is fine. The JIT compiler from Blind Mind Studios does not support the new version of AngelScript. I'll just have to wait until it is updated.
  7. This code that used to work in the previous version of AngelScript now returns a null pointer since updating to version 2.27.0. It's pretty much identical to what's in the manual, so I'm wondering if the method for getting the object pointer has changed since the update. void Object::CallConstructor() { if (constructorCalled) return; asIScriptContext *context = scriptManager->GetContext(); if (context == NULL) return; if (context->Prepare( funcConstructor) < 0) { printf( "There was an error preparing the context.\n"); return; } *((Object**)context->GetAddressOfArg(0)) = this; //AddRef(); int r = context->Execute(); if (r != asEXECUTION_FINISHED) { if (r == asEXECUTION_EXCEPTION) { const char *exception = context->GetExceptionString(); printf( "An Exception, '%s', Occurred In The Constructor.\n", exception); return; } if (r == asERROR) { printf( "An Unexpected Error Occurred In The Constructor.\n"); return; } } else { pScrObj = *((asIScriptObject**)context->GetAddressOfReturnValue());// <--------------------- pScrObj->AddRef(); //Must Be Called or else Pure Virtual Error! context->Unprepare(); constructorCalled = true; } }
  8. asIScriptContext *ScriptManager::GetContext() { asIScriptContext *ctx = NULL; std::vector<asIScriptContext*>::iterator it; if (!contexts.empty()) { for (it = contexts.begin(); it != contexts.end(); ++it) { ctx = *it; if (ctx->GetState() != asEXECUTION_ACTIVE) { return ctx; } } } ctx = engine->CreateContext(); #if defined(_DEBUG) || defined(_DEBUG_RELEASE) peek->AddContext( ctx); #endif contexts.push_back( ctx); return ctx; } I can see how this will cause problems with multiple threads attempting to access a context since it tries to reuse a existing one if it can. Maybe I should read more about threading and try to come up with a more efficient model because right now I'm just constantly creating threads when I could just create the number of execution threads needed and some how feed contexts to them.
  9. I have been using AngelScript in my engine for a while and now I'm trying out its multithreading capabilities. There's not much documentation on this subject, so I'm struggling a bit. I'm trying to acheive a variable amount of threads, maybe 2 or 3, to be used to execute multiple scripts at a given time. The documentation says more than one engine can be used right? Can I only use one? Has anybody had any luck with multithreading with angelscript and does anyone have any sample code available?   I'm trying to keep it as simple as possible:   This is my execution function that my threads call: int threadExecuteContext( void *data) { asIScriptContext *ctx = (asIScriptContext*)data; int r = ctx->Execute(); if (r != asEXECUTION_FINISHED) { if (r == asEXECUTION_EXCEPTION) std::cout << "An exception occurred while executing function on thread id " << SDL_ThreadID() << "." << std::endl; if (r == asEXECUTION_ERROR) std::cout << "An error occurred while executing function on thread id " << SDL_ThreadID() << "." << std::endl; return asERROR; } else { ctx->Unprepare(); } return 0; } This one prepares a function to be called and waits for a available thread: int ScriptManager::ExecuteFunction( asIScriptFunction *func, asIScriptObject *obj) { asIScriptContext *ctx = GetContext(); if (ctx == NULL) return asERROR; if (ctx->Prepare( func) < 0) { std::cout << "Could not prepare script function" << std::endl; return asERROR; } ctx->SetObject( obj); SDL_Thread *th = NULL; while (th == NULL) th = GetThread( ctx); return asSUCCESS; } And lastly here is my GetThread function. It maintains the maximum thread limit by waiting for one to finish: SDL_Thread *ScriptManager::GetThread( asIScriptContext *ctx) { SDL_Thread *th = NULL; if (threads.size() < MAX_THREADS) { th = SDL_CreateThread( threadExecuteContext, "Script Execution Thread", ctx); threads.push_back( th); } else { int returned; thread_iterator it = threads.begin(); SDL_WaitThread( *it, &returned); threads.erase( it); th = SDL_CreateThread( threadExecuteContext, "Script Execution Thread", ctx); threads.push_back( th); } return th; } This method has problems. The context always has an unintialized state and does not execute anything.
  10. I'm trying to convert my engine to use frame rate independent movement. Wouldn't that require that I simply multiply by the amount of time passed?   I'm calculating the frame time like so: double FrameTime = (CurrentTime - LastTime)/1000; double dt = 1.0/fps; And my previous movement code is this: //X Movement x += cos(degtorad(angle)) * x_speed; y -= sin(degtorad(angle)) * x_speed; //Y Movement y += y_speed;     So, would my movement code then change to look more like this: //X Movement x += cos(degtorad(angle)) * (x_speed * FrameTime/dt); y -= sin(degtorad(angle)) * (x_speed * FrameTime/dt); //Y Movement y += (y_speed * FrameTime/dt);   This doesn't produce accurate movements. Rather than this method, should I be considering time when I change speed values, sort of like this: if (left is down) x_speed -= x_acceleration*(FrameTime/dt); if (player not on solid ground) y_speed += gravity*(FrameTime/dt);  
  11. That just might solve it. I currently using #include in each script to define Base_Object. Using shared makes a lot more sense.   EDIT: That fixed it. Thanks!
  12. I solved that frame rate problem. My debug output window was filling up with "accessing null pointer" errors. Now I'm checking for null pointers before I try to access:   for (int i = 0; i < NumLogs; ++i) { int id = create_instance( x+(LogWidth*i), y, objBridgeNode); objBridgeNode_controller @node; Object @obj = get_instance( id); if (obj != null) @node = cast<objBridgeNode_controller>( @obj.GetScriptObject()); else continue; if (node == null) continue; node.ParentBridge = GetId(); node.Id = i; Nodes[i] = id; } Apparently, I'm getting null pointers every time as if the cast operator does not know what type the returned asIScriptObject really is.   Even this doesn't work:   Base_Object_IMP @base = null; base = cast<Base_Object_IMP>( @obj.GetScriptObject());   The result is still null. I know asIScriptObject being passed is valid before hand, so what can this problem be?   Edit:   Here's my other Base_Object class if it helps: class Base_Object : Base_Object_IMP { //========== Constructor / Destructor =========== Base_Object( Object @obj) { @this.object = obj; x = object.x; y = object.y; sprite_index = -1; mask_index = -1; image_index = object.image_index; depth = object.depth; } //=========== Events ============= void Create(){} void Destroy(){} void Alarm1(){} void Alarm2(){} void Alarm3(){} void Alarm4(){} void Alarm5(){} void Alarm6(){} void Alarm7(){} void Alarm8(){} void Alarm9(){} void Alarm10(){} void Alarm11(){} void BeginStep(){} void Step(){} void EndStep(){} void Collision( int objType, int objId, Object @other){} void Key( int key){} void KeyPressed( int key){} void KeyReleased( int key){} void MouseButton( int button){} void MouseButtonPressed( int button){} void MouseButtonReleased( int button){} void JoystickButton( int id, int button){} void JoystickButtonPressed( int id, int button){} void JoystickButtonReleased( int id, int button){} void OutsideRoom(){} void OutsideView(){} void IntersectBoundary(){} void GameStart(){} void GameEnd(){} void RoomStart(){} void RoomEnd(){} void NoMoreLives(){} void NoMoreHealth(){} void AnimationEnd(){} void EndOfPath(){} void Draw(){} //======= Collision ========= bool place_meeting( float mX, float mY, int type) { return object.PlaceMeeting( mX, mY, type); } bool place_meeting_depth( float mX, float mY, int depth, int type) { return object.PlaceMeetingDepth( mX, mY, type, depth); } Base_Object @object_place( float mX, float mY, int type) { Base_Object @base = null; Object @obj = object.ObjectPlace( mX, mY, type); if (obj == null) return null; else //obj.GetScriptObject().retrieve( @base); @base = cast<Base_Object>(@obj.GetScriptObject()); return base; } //========== Misc =========== uint GetId() { return object.GetId(); } void SetRect( int l, int t, int w, int h) { object.general_rect.left = l; object.general_rect.top = t; object.general_rect.right = l+w; object.general_rect.bottom = t+h; } //======= Variables ========= Object @object; float x; float y; int sprite_index; int mask_index; int image_index; int depth; }   classes are declared like: objBridge_controller : Base_Object { .... }
  13. I found that I could do the following:   asIScriptObject *Object::GetScriptObject() { /*CScriptAny *n = new CScriptAny( scriptManager->GetEngine()); int typeId = scriptManager->GetEngine()->GetTypeIdByDecl( "Base_Object_IMP@"); n->Store( pScrObj, typeId); return n;*/ pScrObj->AddRef();//<----- Crashes without calling AddRef return pScrObj; } and then cast like so: int id = create_instance( x+(LogWidth*i), y, objBridgeNode); objBridgeNode_controller @node; Object @obj = get_instance( id); if (obj != null) @node = cast<objBridgeNode_controller>( @obj.GetScriptObject());   Now the problem is the frame rate slowly drops. What could be causing this to happen?
  14. I'm trying to pass a handle of a game object to a script function, but its not working properly.   CScriptAny *Object::GetScriptObject() { CScriptAny *n = new CScriptAny( scriptManager->GetEngine()); int typeId = scriptManager->GetEngine()->GetTypeIdByDecl("Base_Object_IMP@"); n->Store( pScrObj, typeId); return n; } Base_Object_IMP is the interface that the parent class of all scripted game objects, Base_Object inherit. Each instance store a asIScriptObject returned from the constructor. The function above fails with an access violation and it doesn't seem to be able to find the type id for 'Base_Object'.   I'm trying to cast from the base type to a another child type, like so: Base_Object @base = null; Object @obj = find_instance( objPlayer, Player); if (obj != null) obj.GetScriptObject().retrieve( @base); objPlayer_controller @PlayerHandle = cast<objPlayer_controller>( @base);     This is what I'm trying to do: asIScriptObject -> Base_Object_IMP@ -> Base_Object@ -> objPlayer_controller@ (or any other child type).   Is there a proper way to do this?
  15. OpenGL

    <blockquote class='ipsBlockquote'data-author="mhagain" data-cid="5013381" data-time="1356177245"><p> <blockquote class='ipsBlockquote'data-author="justin12343" data-cid="5013246" data-time="1356124157"><p><br /> I trying to avoid taking the shader route for this because I want my engine to be able to run on older hardware.</p></blockquote> Not a direct answer to your question, but I'd strongly urge you to reconsider this. The reason why is: it's now 2012, shaders have been available for over a decade, so: older hardware supports shaders too. In fact, <a href='http://en.wikipedia.org/wiki/OpenGL#OpenGL_2.0'>point sprites are an OpenGL 2.0 feature, and OpenGL 2.0 includes shader support, so if you have support for point sprites then you also have support for shaders</a>.</p></blockquote> Then I guess I'll be taking the shader route. Thanks for the reply!