About Store Forum Documentation Contact



Post Reply 
Destructible object ineisis online
Author Message
Pokan Offline
Member

Post: #1
Destructible object ineisis online
Hey,

I try to set a destruct block on ineisis online, like block and objects in the map in destructible.

Its possible and someone can get me a tutorial?
02-14-2015 08:54 AM
Find all posts by this user Quote this message in a reply
Fex Offline
Gold Supporter

Post: #2
RE: Destructible object ineisis online
Anyways my EE 1.0 Inesis based game used this code, I haven't made destructibles work in EE2+


Code:
/******************************************************************************/
class TimedDestructible : Game.Destructible
{
   Flt creation_time=0.0; // time we made this
   Flt life_time; // how long we should stay before fading away
   MaterialPtr mptr = NULL;
  
   void create(C Str file, C VecI &blockpos, C Vec &impulse, C MaterialPtr &material)
   {
       Box b(Vec(0),Vec(1)); b+=blockpos;

       tactor.create(b, 1).mass(0.1).ccd(true); // make a temporary actor with that matches the blocks matrix
       T.actors.clear();
                    
       Game::ObjParamsPtr obj6=Game::Objs.ptrRequire(file);
       Game.ObjParams obj7= *obj6;
       super.create(obj7); T.matrix(Matrix(tactor.matrix().normalize())); // this creates the destructible object with the tactor's matrix
                    
                    
       REPA(T.actors)
          {
              actors[i].sleep(false).group(AG_BLOCK_SHARD).user(this); // unsleep the shard's physics, set their usergroup and userptr, need this for when we pick them up
          }
                    
       REPA(T.actors)actors[i].addImpulse(Vec(RandomF()),blockpos); // add an impulse so they fly apart
                    
       //if(destruct_mesh)for(int i = 0; i<destruct_mesh.parts();  i++)destruct_mesh.part(i).mesh.setMaterial(material);  // actually we use material lock when we draw the fragments using mptr, so this line is probably not needed.
                    
       mptr =material;
       creation_time = Time.realTime();
       tactor.del();
   }
  
}

void UpdateTimedDestructibles()
{
   REPA(timeddestr)
   {
      if(Time.realTime() - timeddestr[i].creation_time > 10.0)
      {
         timeddestr.removeValid(i);
         return;
      }
   }
}

Actor tactor;
Memx<TimedDestructible> timeddestr;


call UpdateTimedDestructibles(); in your game update


Code:
void ReportContact(ActorInfo &contact_a, ActorInfo &contact_b, C PhysContact *contact, Int contacts)
{
   if(Kb.b(KB_C)) // if we are holding down the 'collect key' and we have made physcial contact, delete the shards
   {
        // CM.New(S+"Collected Shard "+contact_a.group+" "+contact_b.group);
      REPAD(i,timeddestr)
      REPAD(j,timeddestr[i].actors)
      if(timeddestr[i].actors[j].user() == contact_a.user)
      {
         CM.New(S+"You collect a shard.");
         timeddestr.removeValid(i); //CM.New("Removed a shard.");
         return;
      }
   }
}

this was in rendergame(), I have commented it out:

Code:
// EE engine update removed material lock, maybe this isn't possible anymore?
        /*  REPA(timeddestr)for(int j = 0; j<timeddestr[i].destruct_mesh.parts();  j++)
         {
            MaterialLock =  &(*timeddestr[i].mptr);
            timeddestr[i].destruct_mesh.part(j).mesh.draw(timeddestr[i].actors[j].matrix());
            MaterialLock =  NULL;
         }*/

then to communicate from cleint/server so that all users see blocks breaking and disappearing when they are picked up:


on client
Code:
case CS_DESTRUCTIBLE_SPAWN:
            {
              
               Str objfile;  VecI blockpos;  Vec impulse;  Str material;
               ClientRecvDestructibleSpawn(Server.data, objfile, blockpos, impulse, material);
               MaterialPtr mptr; mptr = material;
               // EE 2.0 broke destructibles!
               //timeddestr.New().create(objfile, blockpos, impulse, mptr);
               //CM.New("Recieved CS_DESTRUCTIBLE_SPAWN");
               destroy_particles.New().create(blockpos, Vec(0,1, 0));
              
            } break;

Code:
/******************************************************************************/
// CS_DESTRUCTIBLE_SPAWN
/******************************************************************************/
void ClientSendDestructibleSpawn(Connection &conn, C Str &objfile, C VecI &blockpos, C Vec &impulse, C MaterialPtr &material)
{
   //File f; f.writeMem().putByte(CS_DESTRUCTIBLE_SPAWN).putInt(spell).putStr(target); f.pos(0); conn.dataFull(f, f.left());
   File f; f.writeMem().putByte(CS_DESTRUCTIBLE_SPAWN);
   f.putStr(objfile);
   f.put(&blockpos, SIZE(VecI));
   f.put(&impulse, SIZE(Vec));
   f.putStr(material.name());
   //Gui.msgBox("SendCS_DESTRUCTIBLE_SPAWN","SendCS_DESTRUCTIBLE_SPAWN");
   f.pos(0); conn.send(f, f.left());
}
void ServerRecvDestructibleSpawn(File &f,  Str &objfile,  VecI &blockpos,  Vec &impulse,  Str &material)
{
  // Gui.msgBox("RecvCS_DESTRUCTIBLE_SPAWN","RecvCS_DESTRUCTIBLE_SPAWN");
   objfile = f.getStr();
   f.get(&blockpos, SIZE(VecI));
   f.get(&impulse, SIZE(Vec));
   material = f.getStr();
}
void ServerWriteDestructibleSpawn(File &f, C Str &objfile, C VecI &blockpos, C Vec &impulse, C Str &material)
{
   //Gui.msgBox("SendCS_DESTRUCTIBLE_SPAWN","SendCS_DESTRUCTIBLE_SPAWN");
   f.writeMem().putByte(CS_DESTRUCTIBLE_SPAWN);
   f.putStr(objfile);
   f.put(&blockpos, SIZE(VecI));
   f.put(&impulse, SIZE(Vec));
   f.putStr(material);
}
void ClientRecvDestructibleSpawn(File &f, Str &objfile,  VecI &blockpos,  Vec &impulse,  Str &material)
{
   //Gui.msgBox("RecvCS_DESTRUCTIBLE_SPAWN","RecvCS_DESTRUCTIBLE_SPAWN");
   objfile = f.getStr();
   f.get(&blockpos, SIZE(VecI));
   f.get(&impulse, SIZE(Vec));
   material = f.getStr();
}

on server:

Code:
case CS_DESTRUCTIBLE_SPAWN:
         {
            Str objfile;  VecI blockpos;  Vec impulse;  Str material;
            ServerRecvDestructibleSpawn(connection.data,  objfile,  blockpos,  impulse,  material);
            
            File f;  ServerWriteDestructibleSpawn(f, objfile, blockpos, impulse, material);
            
            if(world())if(Area *data=GetArea(*world(),BlockToArea(blockpos)))
                     {
                        REPA(data.clients)
                        {
                           data.clients[i].send(f);
                        }
                     }
            
         }break;
02-14-2015 10:11 PM
Find all posts by this user Quote this message in a reply
Jben Offline
Member

Post: #3
RE: Destructible object ineisis online
Fex is a Boss of ineisis pfft

Very Thanks for you share! I try you code for EE2 Adapte
(This post was last modified: 02-15-2015 01:20 PM by Jben.)
02-15-2015 10:23 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Jben Offline
Member

Post: #4
RE: Destructible object ineisis online
I add you Code. no error compile but i press C in game is no Work. Im noob sorry.
Just Error in: "destroy_particles.New().create(blockpos, Vec(0,1, 0));" I think call destroy_particles in game.cpp.
02-15-2015 08:08 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Pokan Offline
Member

Post: #5
RE: Destructible object ineisis online
Thanks Fex !

lindsay , if you know how adapt to EE2 , can you make a tutorial.
02-15-2015 08:57 PM
Find all posts by this user Quote this message in a reply
Jben Offline
Member

Post: #6
RE: Destructible object ineisis online
I need help to understand...
02-17-2015 11:39 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Pokan Offline
Member

Post: #7
RE: Destructible object ineisis online
up
03-06-2015 05:07 PM
Find all posts by this user Quote this message in a reply
georgatos7 Offline
Member

Post: #8
RE: Destructible object ineisis online
Hey if using the DestructMesh class is the problem i can post some project files soon enough.
That wont include network functionality though but as you probably have the positions where cudes are getting removed you can easily feed that position to the class and have the fragments spawn at that point.
(This post was last modified: 03-06-2015 10:39 PM by georgatos7.)
03-06-2015 05:56 PM
Find all posts by this user Quote this message in a reply
Post Reply