bool Animation::init( std::string subconfig, std::string config) { std::map < std::string, std::pair <int, int> > anim; LuaConfig* cfg = new LuaConfig; std::string image; cfg->getValue( "height", subconfig, config, height ); cfg->getValue( "width", subconfig, config, width ); cfg->getValue( "image", subconfig, config, image ); cfg->getValue( "picture", subconfig, config, picture ); cfg->getValue( "animation", subconfig, config, anim ); delete cfg; FOREACHIT( anim ){ std::map < std::string, unsigned int >::iterator name = animation_names.find( it->first ); if( name == animation_names.end() ){ name = animation_names.insert( std::pair< std::string, int >( it->first, animation_names.size() + 1 ) ).first; } GROW_ARRAY( animation, AnimationFrames, name->second, animationSize ) animation[name->second].start = it->second.first; animation[name->second].end = it->second.second; } sprite = RenderManager::CreateGLSprite( 0, 0, 0, width, height, RenderManager::GetTextureNumberById( image ), picture); sprite->setCentered(); sprite->setPicture( picture ); count = 0; return true; }
void TextureAtlas::addTexture( std::string name ){ LuaConfig* lc = new LuaConfig; std::string config = "sprite"; TextureProxy* t = new TextureProxy(); lc->getValue("id", name, config, t->id); lc->getValue("image", name, config, t->image); lc->getValue("width", name, config, t->abs.width); lc->getValue("height", name, config, t->abs.height); lc->getValue("rows", name, config, t->rows); lc->getValue("columns", name, config, t->cols); lc->getValue("offsetx", name, config, t->offset.x); lc->getValue("offsety", name, config, t->offset.y); t->texture = GLTextures::load( t->image ); internalTextures.push_back(t); delete lc; }
bool WidgetBar::load( std::string id ) { if( !WidgetText::load( id ) ) return false; std::string imgname; int picture; int barheight; color4u color; std::vector<int> vcolor; LuaConfig* cfg = new LuaConfig; //Order: topimgx, topimgy, barheight, r, g, b //Ya, it's cruve, but it's simple cfg->getValue( "barheight", id, barheight ); cfg->getValue( "barwidth", id, BarWidth ); cfg->getValue( "barx", id, BarX ); cfg->getValue( "bary", id, BarY ); cfg->getValue( "topimage", id, imgname ); cfg->getValue( "toppicture", id, picture ); cfg->getValue( "barcoverx", id, TopX ); cfg->getValue( "barcovery", id, TopY ); cfg->getValue( "barcolor", id, vcolor ); for( unsigned int i=0; i < 3; ++i ){ if( i >= vcolor.size() ) vcolor.push_back(0); } color.set( (unsigned)vcolor[0], (unsigned)vcolor[1], (unsigned)vcolor[2] ); if( BarWidth <= 0 ) BarWidth = (float)Width; createBar( imgname, picture, barheight, color ); updatePosition(); delete cfg; return true; }
bool Unit::Create( int id, std::string proto ) { UnitId = id; if( !setUnitName( TypeName ) ) return false; if( !Image.init( UnitName, TypeName ) ) return false; if( proto == "" ){ LuaConfig* cfg = new LuaConfig; cfg->getValue( "proto", UnitName, TypeName, proto ); delete cfg; } if( proto == "" ){ Debug::debug( Debug::UNIT, "Unit with blank prototype, creation failed. UID: " + citoa(UnitId) + ".\n" ); return false; } { ProtoManager* pm = new ProtoManager; Actions.setProto( pm->GetProtoByName( proto ) ); Actions.setAction( "init" ); delete pm; if( !Actions.loaded ){ Debug::debug( Debug::UNIT, "Unit with invalid prototype '" + proto + "'. Creation failed. UID: " + citoa(UnitId) + ".\n" ); return false; } } // Create physics if( Actions.proto->statical ){ physBody = cpBodyNewStatic(); }else{ physBody = cpBodyNew( 1.0, 1.0 ); physBody = cpSpaceAddBody( Phys::space, physBody ); } physBody->data = this; if( Actions.proto->physicsType >= 0 && Actions.proto->physicsType < potLast ) phys.type = (enum PhysObectType)Actions.proto->physicsType; else{ Debug::debug( Debug::UNIT, "Bad physics object type: " + citoa( Actions.proto->physicsType ) + ".\n" ); phys.type = potNone; } cpShape* shape = NULL; switch( phys.type ){ case potCircle: shape = cpCircleShapeNew( physBody, phys.radius, cpvzero ); break; case potQuad: shape = cpBoxShapeNew( physBody, phys.sides.x, phys.sides.y ); break; default: break; } if( shape != NULL ){ physShape = cpSpaceAddShape( Phys::space, shape ); physShape->collision_type = UnitType; } //physBody->velocity_func = call_velocity_func; return true; }
bool Unit::update( const Frame& frame ) { const StackData& param = frame.params[0]; switch(frame.command){ case acNone: break; // Functions case acSuper: Actions.saveState( true ); Actions.setParentAction( param.stringData ); break; case acRestoreState: // This is return for acSuper command. It does nothing if no saved state . Actions.restoreState(); break; case acSetAction: // If param is not null, it will be action call, not replacing if( Actions.checkFrameParams( frame, 1, stStringOrNone ) ){ Actions.setAction( param.stringData ); return false; } break; case acSetTimer: if( Actions.checkFrameParams( frame, 2, stFunction, stInt ) ){ ActionTimer* timer = actionTimers; const Frame* pframe = &frame; while( timer != NULL ){ if( timer->frame == pframe ) break; timer = timer->next; } if( !timer || !Timer::UpdateEventById( timer->timerId, frame.params[1].intData) ){ if( timer ){ ActionTimer* oldtimer = actionTimers; while( timer != NULL ){ // ActionTimer is deleted from manager. Delete it from holder. if( oldtimer->next == timer ){ oldtimer->next = oldtimer->next->next; delete timer, timer = NULL; break; } timer = timer->next; } } IActionTimer* t = new IActionTimer( this, param.intData ); actionTimers = new ActionTimer( pframe, t, actionTimers ); actionTimers->timerId = Timer::AddInternalTimerEvent( t, frame.params[1].intData ); } } break; // Action parameters stack case acPushInt: Actions.params.Push( param.intData ); break; case acPushFloat: //TODO: float Actions.params.Push( param.intData ); Debug::debug( Debug::PROTO, "acPushFloat not implemented.\n" ); break; case acPushString: Actions.params.Push( param.stringData ); break; case acPush: for( int i = 0; i < FRAME_PARAMS_COUNT; ++i ){ switch( frame.param_types[i] ){ case stInt: Actions.params.Push( frame.params[i].intData ); break; case stString: Actions.params.Push( frame.params[i].stringData ); break; default: break; } } break; // Conditions case acCondition: // acCondition always false Actions.frame = frame.condition_end; break; case acEnd: // Do nothing break; case acIfParamEqual: PARAMCOND( != ) break; case acIfParamLess: PARAMCOND( > ) break; case acIfParamMore: PARAMCOND( < ) break; case acIfParametersEqual: PARAMSCOND( != ) break; case acIfParametersLess: PARAMSCOND( > ) break; case acIfParametersMore: PARAMSCOND( < ) break; case acIfParametersLessBy: PARAMSCOND( + param.intData > ) break; // Unit flags case acIfFlag: CHECKFLAG if( !( flags & param.intData ) ) Actions.frame = frame.condition_end; break; case acIfNotFlag: CHECKFLAG if( flags & param.intData ) Actions.frame = frame.condition_end; break; case acSetFlag: CHECKFLAG flags |= param.intData; break; case acRemoveFlag: CHECKFLAG flags &= ~param.intData; break; // Unit Parameters case acSetParam: if( Actions.checkFrameParams( frame, 2, stInt, stInt ) ) Char.set( param.intData, (float)frame.params[1].intData ); else Debug::debug( Debug::PROTO, "acSetParam bad parameter name.\n" ); break; case acCopyParam: if( !Actions.checkFrameParams( frame, 2, stInt, stInt ) ) Debug::debug( Debug::PROTO, "acCopyParam bad original parameter name.\n" ); else if( !param.intData ) Debug::debug( Debug::PROTO, "acCopyParam bad parameter name.\n" ); else Char.set( param.intData, Char.get( frame.params[1].intData ) ); break; case acLoadParam: { if( !Actions.checkFrameParams( frame, 2, stInt, stString ) ) break; LuaConfig* cfg = new LuaConfig; if( param.intData < uCharIntLast ) cfg->getValue( frame.params[1].stringData, UnitName, TypeName, Char.getRef( (enum character)param.intData ) ); else cfg->getValue( frame.params[1].stringData, UnitName, TypeName, Char.getRef( (enum character_float)param.intData ) ); delete cfg; break; } case acLoadParamBunch: { if( param.intData <= 0 ) break; LuaConfig* cfg = new LuaConfig; for( int i = 0; i < param.intData; i++ ){ if( !Actions.params.CheckParamTypes( 2, stInt, stString ) ){ Debug::debug( Debug::PROTO, "acLoadPraramBunch wrong " + citoa(i+1) + " parameter set.\n" ); continue; } int psparam = Actions.params.PopInt(); if( psparam < uCharIntLast ) cfg->getValue( Actions.params.PopString(), UnitName, TypeName, Char.getRef( (enum character)psparam ) ); else cfg->getValue( Actions.params.PopString(), UnitName, TypeName, Char.getRef( (enum character_float)psparam ) ); } delete cfg; break; } // Physics case acSetUnitPhysics: if( Actions.checkFrameParams( frame, 3, stInt, stInt, stIntOrNone ) ){ int firstparam = frame.params[1].intData; switch(param.intData){ case pptMat: break; case pptRadius: phys.radius = firstparam; break; case pptSides: phys.sides.x = firstparam; phys.sides.y = frame.params[2].intData; break; } phys.calc_mass(); updatePhysics( ); } break; case acSetPhysicsLayer: if( Actions.checkFrameParams( frame, 1, stInt ) && physShape != NULL ) cpShapeSetGroup( physShape, param.intData ); break; // Misc case acSetUnitSize: if( Actions.checkFrameParams( frame, 1, stInt ) ) setUnitSize( static_cast<float>(param.intData) / 100 ); break; case acSetColor: if( Actions.checkFrameParams( frame, 4, stInt, stInt, stInt, stInt ) ) Image.getSprite()->clr.set( frame.params[0].intData, frame.params[1].intData, frame.params[2].intData, frame.params[3].intData ); break; default: return false; } return true; }
bool MainConfig::load( ) { LuaConfig* lc = new LuaConfig; std::string id; std::string config; id = "config_general"; config = "config"; lc->getValue( "windows_width" , id, config, windowWidth ); lc->getValue( "windows_height" , id, config, windowHeight ); lc->getValue( "maximum_frame_rate" , id, config, maxFrameRate ); lc->getValue( "minimum_frame_rate" , id, config, minFrameRate ); lc->getValue( "texture_border" , id, config, textureBorder ); lc->getValue( "images_path" , id, config, imagePath ); lc->getValue( "default_image_name" , id, config, defaultImage ); lc->getValue( "fonts_path" , id, config, fontsPath ); lc->getValue( "scripts_path" , id, config, scriptsPath ); lc->getValue( "configs_path" , id, config, configsPath ); lc->getValue( "proto_path" , id, config, protoPath ); lc->getValue( "shaders_path" , id, config, shadersPath ); lc->getValue( "widgets_z" , id, config, widgetsPosZ ); lc->getValue( "map_tile_size" , id, config, mapTileSize ); lc->getValue( "map_default_tile" , id, config, mapDefaultTile ); lc->getValue( "day_length" , id, config, dayLength ); lc->getValue( "action_interval" , id, config, actionInterval ); lc->getValue( "max_spawn" , id, config, maxSpawn ); lc->getValue( "max_edibles" , id, config, maxEdibles ); lc->getValue( "player_dies" , id, config, playerDies ); delete lc; float right = (float)(mapTileSize >> 2); float bottom = (float)(mapTileSize >> 1); float tile_side = sqrt( right * right + bottom * bottom ); _tileAngle = asin( right / tile_side ); return true; };