Would you like to react to this message? Create an account in a few clicks or log in to continue.



 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

 

 [SPARK 2] Bug Report

Go down 
+5
Darktib
shd
stardeath
Juff
Charlie
9 posters
Go to page : 1, 2, 3  Next
AuthorMessage
Charlie




Messages : 81
Date d'inscription : 2011-01-28
Age : 42

[SPARK 2] Bug Report Empty
PostSubject: [SPARK 2] Bug Report   [SPARK 2] Bug Report Icon_minitimeTue Nov 01, 2011 7:16 am

Hi Juff ! I decided to use the SPARK2 serialization system instead of my binary save because of the xml format , and it works nice except the renderers... i've tried to add the descriptors and methods

The export works fine but there's a problem with import (after loading the file , the groups renderer is always NULL however they are exported correctly in the file)
This is what i've done so far (rough):

DX9QuadRenderer.h :

Code:
SPK_IMPLEMENT_OBJECT(DX9QuadRenderer)
SPK_START_DESCRIPTION
SPK_PARENT_ATTRIBUTES(SPKObject)
SPK_ATTRIBUTE("quad size",ATTRIBUTE_TYPE_FLOATS)
SPK_ATTRIBUTE("atlas dimensions",ATTRIBUTE_TYPE_UINT32S)
SPK_ATTRIBUTE("texture name",ATTRIBUTE_TYPE_STRING)
SPK_ATTRIBUTE("blending enabled",ATTRIBUTE_TYPE_BOOL)
SPK_END_DESCRIPTION

// and the methods
protected :

      virtual void innerImport(const IO::Descriptor& descriptor);
      virtual void innerExport(IO::Descriptor& descriptor) const;


DX9QuadRenderer.cpp :

Code:
void DX9QuadRenderer::innerExport(IO::Descriptor& descriptor) const
   {
      SPKObject::innerExport(descriptor);

      float scx = getScaleX();
      float scy = getScaleY();
      uint32 atlx = getAtlasDimensionX();
      uint32 atly = getAtlasDimensionY();

      float tmpQuadSize[2] = {scx,scy};
      uint32 tmpAtlas[2] = {atlx,atly};

      descriptor.getAttribute("quad size")->setValues(tmpQuadSize,2);
      descriptor.getAttribute("atlas dimensions")->setValues<uint32>(tmpAtlas,2);
      descriptor.getAttribute("texture name")->setValue(getTextureName());
      descriptor.getAttribute("blending enabled")->setValue(isBlendingEnabled());
   }


   void DX9QuadRenderer::innerImport(const IO::Descriptor& descriptor)
   {
      SPKObject::innerImport(descriptor);

      const IO::Attribute* attrib = NULL;

      if (attrib = descriptor.getAttributeWithValue("quad size"))
      {
         std::vector<float> tmpSize = attrib->getValues<float>();
         setScale(tmpSize[0],tmpSize[1]);
      }
         
      if (attrib = descriptor.getAttributeWithValue("atlas dimensions"))
      {
         std::vector<uint32> tmpAtlas = attrib->getValues<uint32>();
         setAtlasDimensions(tmpAtlas[0],tmpAtlas[1]);
      }

      if (attrib = descriptor.getAttributeWithValue("texture name"))
         setTextureName(attrib->getValue<std::string>());

      if (attrib = descriptor.getAttributeWithValue("blending enabled"))
      {
         enableBlending(attrib->getValue<bool>());
         if (isBlendingEnabled()) setBlendMode(BLEND_MODE_ADD);
         setTexture(NULL);
      }


   }
After the system is successfully loaded the renderer is NULL... any good advice ? Thanks !

Please note that i added getTextureName() and setTextureName() to SPK_QuadRenderBehavior and SPK_PointRenderBehavior for storing the texture path and name , also the blendMode isn't finished yet i just want to test it so the dest blending and src blending currently not stored...
Back to top Go down
Juff
Developer



Messages : 539
Date d'inscription : 2009-07-14
Age : 41

[SPARK 2] Bug Report Empty
PostSubject: Re: [SPARK 2] Bug Report   [SPARK 2] Bug Report Icon_minitimeTue Nov 01, 2011 8:34 am

Hi, I think that s because you did not register the class in the IO manager (It is not needed for saving but only for loading so that the manager can create an instance). You must call that line once before any import using DX9QuadRenderer :

Code:
SPK::IO::IOManager::get().registerObject<SPK::DX9::DX9QuadRenderer>();

The SPARK logger should have told you that when loading though with a :
Code:
The type "DX9QuadRenderer" is not registered

Otherwise your code seems correct, except the parent of DX9QuadRenderer should be Renderer and not SPKObject (so that renderer specific attributes are exported/imported) :

Code:

// Here
SPK_PARENT_ATTRIBUTES(Renderer)

// And here
void DX9QuadRenderer::innerExport(IO::Descriptor& descriptor) const
{
  Renderer::innerExport(descriptor);

// And here
void DX9QuadRenderer::innerImport(const IO::Descriptor& descriptor)
{
  Renderer::innerImport(descriptor);

@Devilwithin : Can you tell me more about it ? Is it SPARK 1 or SPARK 2 ?
Back to top Go down
http://spark.developpez.com
Charlie




Messages : 81
Date d'inscription : 2011-01-28
Age : 42

[SPARK 2] Bug Report Empty
PostSubject: Thanks   [SPARK 2] Bug Report Icon_minitimeTue Nov 01, 2011 10:33 am

Thanks Juff ! now works fine !

i found a bug in RandomInterpolator serialization :


when i save a system which has a RandomInterpolator (both Float and Color) the values are Ok but when i load it back the values are messed up :
(The SPK_LOG_ERROR says that there are "Wrong number of values" Note :The "objectType" id is a value used in my wrapper and is added in SPKObject's serialization)


Original (first save) :


Code:
- <ColorRandomInterpolator>
  <attrib id="shared" value="true" />
  <attrib id="objectType" value="106" /> 
  <attrib id="values" value="0xffffb2ff;0xffffb2ff;0xff4c4c00;0xffff4c00" />
  </ColorRandomInterpolator>

Code:
- <FloatRandomInterpolator>
  <attrib id="shared" value="true" />
  <attrib id="objectType" value="109" />
  <attrib id="values" value="0.6;0.8;1;1.4" />
  </FloatRandomInterpolator>


When i load the file and save it again it will look like this :

Code:
- <ColorRandomInterpolator>
  <attrib id="shared" value="true" />
  <attrib id="objectType" value="106" />
  <attrib id="values" value="0xffffffff;0xffffffff;0xffffffff;0xffffffff" />  // saves this value
  </ColorRandomInterpolator>


Code:
- <FloatRandomInterpolator>
  <attrib id="shared" value="true" />
  <attrib id="objectType" value="109" />
  <attrib id="values" value="0;0;0;0" /> // always 0
  </FloatRandomInterpolator>
Back to top Go down
Juff
Developer



Messages : 539
Date d'inscription : 2009-07-14
Age : 41

[SPARK 2] Bug Report Empty
PostSubject: Re: [SPARK 2] Bug Report   [SPARK 2] Bug Report Icon_minitimeTue Nov 01, 2011 11:30 am

Thanks it is fixed in the latest svn
Back to top Go down
http://spark.developpez.com
Charlie




Messages : 81
Date d'inscription : 2011-01-28
Age : 42

[SPARK 2] Bug Report Empty
PostSubject: HI!   [SPARK 2] Bug Report Icon_minitimeTue Nov 01, 2011 2:49 pm

hi it's me again (for a change Very Happy )

I'm not sure ,but it seems that theres a problem with importing the SPKObject name too
are the "_" or "|" or the "\" "/" characters allowed in a system name ? it's hard to describe this issue and it isn't permanent but i found out that mostly these character will cause it.

here's an example

saved system : (everything is ok)

Code:
- <SPARK>
- <System name="media_explosion_1">

and the system loaded back (the name contains some random invalid characters + they're messed up):

Code:
<SPARK>
   <System name="�8$a_explosion_1">

Everything works nice at runtime (setName() and getName() returns the correct string)


Thanks in advance

PS : Oh and what are your plans for the renderer's texture serialization ? adding a textureName string to the specific renderer (like i did) or something else ? because if you use the get/set textureName solution too then i will wait for your release instead of extending SPARK2 unofficially ...

Thanks
Back to top Go down
Juff
Developer



Messages : 539
Date d'inscription : 2009-07-14
Age : 41

[SPARK 2] Bug Report Empty
PostSubject: Re: [SPARK 2] Bug Report   [SPARK 2] Bug Report Icon_minitimeTue Nov 01, 2011 5:43 pm

When you say it isnt permanent what do you mean ? Is it deterministic ?
If you can provide me with the complete xml file, I will investigate. Thanks
Back to top Go down
http://spark.developpez.com
Charlie




Messages : 81
Date d'inscription : 2011-01-28
Age : 42

[SPARK 2] Bug Report Empty
PostSubject: xml files   [SPARK 2] Bug Report Icon_minitimeTue Nov 01, 2011 7:47 pm

Here are the xml files . Generated with the latest version from the SVN.

This is the file which is OK (saved)

Saved file

and it looks like this when you load it back again (My browser can't even show this file... try with notepad or wordpad) :

Re-saved file

When i said permanent i meant to say , this issue shows up randomly.If i remove the _ characters then it works !
Like try set the name to "media_explosion" then it works fine

but "mediaexplosion__" not working.

same issue with these characters : ". , \ | / *" if the string contains MORE THAN ONE of these chars


The code i used to generate the xml :

Code:
Ref<System> ts = System::create();
ts->setName("media**explosion"); // try to change ** to * then it works

Ref<Group> gr = Group::create();
      
gr->setParamInterpolator(PARAM_SCALE , FloatRandomInterpolator::create(0.1f,2.0f,3.1f,12.0f));
gr->addEmitter(StaticEmitter::create(Point::create(Vector3D(0,0,0)),true,-1,1));

ts->addGroup(gr);

SPK::IO::IOManager::get().save("SystemTest.xml",ts);
Ref<System> ns = SPK::IO::IOManager::get().load("SystemTest.xml");
SPK::IO::IOManager::get().save("SystemTest_wrong.xml",ns);

Cheers
Back to top Go down
Juff
Developer



Messages : 539
Date d'inscription : 2009-07-14
Age : 41

[SPARK 2] Bug Report Empty
PostSubject: Re: [SPARK 2] Bug Report   [SPARK 2] Bug Report Icon_minitimeWed Nov 02, 2011 3:55 pm

Thanks,
There was a bug about string serialization in my code.
Should be fixed in the latest version on svn
Back to top Go down
http://spark.developpez.com
Charlie




Messages : 81
Date d'inscription : 2011-01-28
Age : 42

[SPARK 2] Bug Report Empty
PostSubject: thanks   [SPARK 2] Bug Report Icon_minitimeWed Nov 02, 2011 6:39 pm

thank you ! Just tested and works perfectly
Back to top Go down
Charlie




Messages : 81
Date d'inscription : 2011-01-28
Age : 42

[SPARK 2] Bug Report Empty
PostSubject: Hi   [SPARK 2] Bug Report Icon_minitimeSat Nov 05, 2011 9:52 pm

Hi i found another issue in the color interpolators (simple interpolator and random interpolator)

When you set the the group's min and max lifetime very close to each other (or equal) , the particles flickering right after the group becomes inactive. I can't explain exacly what's happening so i linked a video and a small code to test.

Here's a video of it (this is the explosion demo from SPARK1 ported to SPARK2 + i added an emitter attacher modifier to it ) watch the sparks and the trails (emitter attacher)

VIDEO

PS: i thought it was the emitter attacher causing this problem but the same thing happens without the emitter attacher

and here's a simple demo to test : (i used GLQuadRenderer and the latest version from svn)

Code:
SPK::Ref<SPK::System> system = SPK::System::create(true);

SPK::Ref<SPK::GL::GLQuadRenderer> renderer = SPK::GL::GLQuadRenderer::create(4.0f,4.0f);
renderer->setBlendMode(SPK::BLEND_MODE_ADD);
renderer->enableRenderingOption(SPK::RENDERING_OPTION_DEPTH_WRITE,false);
renderer->setTexture(textureParticle);
renderer->setTexturingMode(SPK::TEXTURE_MODE_2D);

SPK::Ref<SPK::Group> group = system->createGroup(50);
group->setLifeTime(0.9f,0.9f);    // try setting the min a bit lower value
group->setRadius(0.01f);
group->setRenderer(renderer);
group->setColorInterpolator(SPK::ColorSimpleInterpolator::create(0xFF802080,0x00AA0000)); //
group->addEmitter(SPK::RandomEmitter::create(SPK::Point::create(),true,20,-1,0.2f,0.7f));







Back to top Go down
Juff
Developer



Messages : 539
Date d'inscription : 2009-07-14
Age : 41

[SPARK 2] Bug Report Empty
PostSubject: Re: [SPARK 2] Bug Report   [SPARK 2] Bug Report Icon_minitimeSun Nov 06, 2011 6:08 am

Hi, I ll take a look a that.

Seems like the alpha value is wrapping around.

By the way, nice use of the emitter attacher !

PS : I have split the post in 2 with a new section for bug reporting to distinguish between bugs and new features anouncement for SPARK 2
Back to top Go down
http://spark.developpez.com
Juff
Developer



Messages : 539
Date d'inscription : 2009-07-14
Age : 41

[SPARK 2] Bug Report Empty
PostSubject: Re: [SPARK 2] Bug Report   [SPARK 2] Bug Report Icon_minitimeSun Nov 06, 2011 7:49 am

It should be fixed on the svn.
Thanks for the report.
Back to top Go down
http://spark.developpez.com
Charlie




Messages : 81
Date d'inscription : 2011-01-28
Age : 42

[SPARK 2] Bug Report Empty
PostSubject: Hi   [SPARK 2] Bug Report Icon_minitimeWed Nov 09, 2011 12:38 am

Hi Juff i'm affraid this time i've run into a bigger problem :
(this isn't really a SPARK2 bug as you said that the DX9 module is officially not part of SPARK2...)

If i combine 2 different DX9 renderers in a system there are some strange glitches on quads :
a system consists of a quad renderer and a line trail renderer causes this problem.
Here are some screenshots :

[SPARK 2] Bug Report Bug1s11

[SPARK 2] Bug Report Bug2s10

There's also a problem with the order of rendering . if you render lines after quads , particles are not visible on screen
here's some pseudo code:

Code:
// this works but causes the glitches like on the screenshots

system->addGroup(groupWithLineTrailRenderer)
system->addGroup(groupWithQuadRenderer)

// particles are not visble
system->addGroup(groupWithQuadRenderer)
system->addGroup(groupWithLineTrailRenderer)

Regards
Back to top Go down
stardeath
Committer



Messages : 140
Date d'inscription : 2009-08-24

[SPARK 2] Bug Report Empty
PostSubject: Re: [SPARK 2] Bug Report   [SPARK 2] Bug Report Icon_minitimeWed Nov 09, 2011 6:42 am

hello, do you have a minimal source code to reproduce the problem, i will try to correct it.
Back to top Go down
Charlie




Messages : 81
Date d'inscription : 2011-01-28
Age : 42

[SPARK 2] Bug Report Empty
PostSubject: Hi   [SPARK 2] Bug Report Icon_minitimeWed Nov 09, 2011 8:27 am

Hi ! You can test with BasicDemoDX9.However the issue only exists in my wrapper.The c++ version (BasicDemoDX9) has another/similar issue.if The Quad renderer's texturingMode is set to TEXTURE_MODE_2D ,the lines are not visible anymore...
Here's the complete source code of BasicDemoDX9.cpp , i've modified it a bit because its missing some elements :
-The line trail renderer had no Emitter (added)
-The texture is not available in "res" folder for the quad renderer (i changed it to flare.bmp)
-I set the texturingMode to TEXTURE_MODE_2D

copy/paste the code below to BasicDemoDX9.cpp :
if you comment out Line 309 (g_pQuadRenderer->setTexturingMode(SPK::TEXTURE_MODE_2D)) Both lines and Quads are visible.If you uncomment Line 309 Only the quads are visible

BasicDemoDX9.cpp (Modified) :

Code:
//////////////////////////////////////////////////////////////////////////////////
// SPARK particle engine                                          //
// Copyright (C) 2009-2010 - foulon matthieu - stardeath@wanadoo.fr            //
//                                                            //
// This software is provided 'as-is', without any express or implied         //
// warranty.  In no event will the authors be held liable for any damages      //
// arising from the use of this software.                              //
//                                                            //
// Permission is granted to anyone to use this software for any purpose,      //
// including commercial applications, and to alter it and redistribute it      //
// freely, subject to the following restrictions:                        //
//                                                            //
// 1. The origin of this software must not be misrepresented; you must not      //
//    claim that you wrote the original software. If you use this software      //
//    in a product, an acknowledgment in the product documentation would be      //
//    appreciated but is not required.                                 //
// 2. Altered source versions must be plainly marked as such, and must not be   //
//    misrepresented as being the original software.                     //
// 3. This notice may not be removed or altered from any source distribution.   //
//////////////////////////////////////////////////////////////////////////////////

#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <ctime>

#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#include <d3dx9.h>

#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")
#pragma comment(lib, "dxerr.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "comctl32.lib")

#define USE_SPARK




#include "CTimer.h"
CTimer g_timerDemo;

#include "CCamera.h"
CGlobalCamera *g_pCamera;

#ifndef SAFE_DELETE
#define SAFE_DELETE(p)      { if (p) { delete (p);    (p)=NULL; } }
#endif   
#ifndef SAFE_DELETE_ARRAY
#define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p);  (p)=NULL; } }
#endif   
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(p)      { if (p) { (p)->Release(); (p)=NULL; } }
#endif

// trace allocations under windows
/*
#if defined(DEBUG) | defined(_DEBUG)
#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#define new new(_CLIENT_BLOCK,__FILE__,__LINE__)
#endif
//*/

#ifdef USE_SPARK
#include <SPARK.h>
#include <SPARK_DX9.h>
#endif // USE_SPARK


using namespace std;




#ifdef USE_SPARK
SPK::Ref<SPK::System> g_pSystem;

SPK::DX9::DX9QuadRenderer* g_pQuadRenderer = NULL;
SPK::DX9::DX9LineTrailRenderer* g_pLineTrailRenderer = NULL;
SPK::DX9::DX9PointRenderer* g_pPointRenderer = NULL;

SPK::Ref<SPK::RandomEmitter> g_pEmitter;
SPK::Ref<SPK::Gravity> g_pGravity;
SPK::Ref<SPK::Friction> g_pFriction;
SPK::Ref<SPK::ColorGraphInterpolator> g_pGraphInterpolator;
SPK::Ref<SPK::Obstacle> g_pObstacle;

SPK::Ref<SPK::Group> g_pGroup1;
SPK::Ref<SPK::Group> g_pGroup2;
#endif














float step = 0.0f;

const string STR_NB_PARTICLES = "NB PARTICLES : ";
const string STR_FPS = "FPS : ";

string strNbParticles = STR_NB_PARTICLES;
string strFps = STR_FPS;

int screenWidth;
int screenHeight;
float screenRatio;

int drawText = 2;

HWND g_hWnd;
HINSTANCE g_hInst;
int g_iLargeur, g_iHauteur;
LPDIRECT3D9 g_pD3D;
LPDIRECT3DDEVICE9 g_pD3DDevice;
D3DPRESENT_PARAMETERS g_D3Dpp;

LPD3DXMESH g_pMesh;

D3DLIGHT9 g_light;

HRESULT hr;

POINT g_ptSourisPosition;
bool g_bSourisDroite;

LPDIRECT3DTEXTURE9 textureParticle = NULL;

void Init();
void UnInit();

LRESULT CALLBACK MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

HRESULT CreateWnd(HINSTANCE hInst, int largeur, int hauteur)
{   
   g_hInst = hInst;
   g_iLargeur = largeur;
   g_iHauteur = hauteur;
   
   WNDCLASSEX wc;// = {sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, hInst, NULL, NULL, NULL, "test", NULL};

   wc.lpszClassName = "SPARKDemoBasicDX9"; // The name of our new window class
    wc.cbSize        = sizeof(WNDCLASSEX); // Specifies the size, in bytes, of this structure
    wc.style        = CS_CLASSDC;//*/CS_HREDRAW | CS_VREDRAW; // Specifies the class style(s)
    wc.lpfnWndProc  = MsgProc; // The name of our call back function
    wc.hInstance    = g_hInst;  // Instance of this application
    wc.hIcon        = LoadIcon(NULL, IDI_APPLICATION); // Don't set any icons
    wc.hIconSm      = LoadIcon(NULL, IDI_APPLICATION); // We'll use the defaults
    wc.hCursor      = LoadCursor(NULL, IDC_ARROW); // Use the standard arrow cursor
    wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); // Fill client-area with black
    wc.lpszMenuName  = NULL; // Our application has no menu
    wc.cbClsExtra    = 0; // Specifies the number of extra bytes to allocate following the window-class structure
    wc.cbWndExtra    = 0; // Specifies the number of extra bytes to allocate following the window instance
   
   if( !RegisterClassEx(&wc) ) return E_FAIL;

   g_hWnd = CreateWindow("SPARKDemoBasicDX9", "SPARK Demo Basic DX9", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, g_iLargeur, g_iHauteur, NULL, NULL, g_hInst, NULL);
   
   if( g_hWnd == NULL ) return E_FAIL;

   ShowWindow(g_hWnd, SW_SHOW);

   UpdateWindow(g_hWnd);

    return S_OK;
}

HRESULT InitDX(int largeur, int hauteur, bool bPleinEcran)
{
   g_pD3D = Direct3DCreate9( D3D_SDK_VERSION );

   if( g_pD3D == NULL )
   {
      // TO DO: Respond to failure of Direct3DCreate9
      return E_FAIL;
   }

    D3DDISPLAYMODE d3ddm;

    if( FAILED( g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) )
   {
      // TO DO: Respond to failure of GetAdapterDisplayMode
      return E_FAIL;
   }

   HRESULT hr;

   D3DDEVTYPE DeviceType = D3DDEVTYPE_HAL;
   DWORD dwBehaviorFlags = 0;

   if( FAILED( hr = g_pD3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, DeviceType,
                                    d3ddm.Format, D3DUSAGE_DEPTHSTENCIL,
                                    D3DRTYPE_SURFACE, D3DFMT_D16 ) ) )
   {
      if( hr == D3DERR_NOTAVAILABLE )
         // POTENTIAL PROBLEM: We need at least a 16-bit z-buffer!
         cout << "pas de z-buffer 16 bits" << endl;
         return E_FAIL;
   }

   D3DCAPS9 d3dCaps;

   if( FAILED( g_pD3D->GetDeviceCaps( D3DADAPTER_DEFAULT,
                                    DeviceType, &d3dCaps ) ) )
   {
      // TO DO: Respond to failure of GetDeviceCaps
      cout << "GetDeviceCaps fails" << endl;
      return E_FAIL;
   }

   if( d3dCaps.VertexProcessingCaps != 0 )
      dwBehaviorFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
   else
      dwBehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;

   memset(&g_D3Dpp, 0, sizeof(g_D3Dpp));

   g_D3Dpp.BackBufferFormat      = d3ddm.Format;
   g_D3Dpp.SwapEffect            = D3DSWAPEFFECT_DISCARD;
   g_D3Dpp.Windowed              = TRUE;
    g_D3Dpp.EnableAutoDepthStencil = TRUE;
    g_D3Dpp.AutoDepthStencilFormat = D3DFMT_D16;
    g_D3Dpp.PresentationInterval  = D3DPRESENT_INTERVAL_IMMEDIATE;

   if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, DeviceType, g_hWnd, dwBehaviorFlags|D3DCREATE_MULTITHREADED, &g_D3Dpp, &g_pD3DDevice ) ) )
   {
      // TO DO: Respond to failure of CreateDevice
      cout << "CreateDevice fails" << endl;
      return E_FAIL;
   }

#ifdef USE_SPARK
   SPK::DX9::DX9Info::setDevice(g_pD3DDevice);
#endif
   
   return S_OK;
}


// Converts an int into a string
string int2Str(int a)
{
    ostringstream stm;
    stm << a;
    return stm.str();
}


void Init()
{
   hr = D3DXCreateTextureFromFile(g_pD3DDevice, "res/flare.bmp", &textureParticle);
   if( FAILED(hr) )
      cout << "erreur chargement texture" << endl;


   ///////////////
   // D3D Setup //
   ///////////////

   g_pCamera = new CGlobalCamera();

   D3DXMATRIX mWorld;
   D3DXMatrixIdentity(&mWorld);
   g_pD3DDevice->SetTransform(D3DTS_WORLD, &mWorld);

   D3DXCreateSphere(g_pD3DDevice, 1.0f, 4, 4, &g_pMesh, NULL);

   D3DVECTOR Vdir = {0,-1,0};
   memset(&g_light,0,sizeof(D3DLIGHT9));
   g_light.Type = D3DLIGHT_DIRECTIONAL;
   g_light.Diffuse.r = 1.0f;
   g_light.Diffuse.g = 1.0f;
   g_light.Diffuse.b = 1.0f;
   g_light.Diffuse.a = 1.0f;
   g_light.Direction = Vdir;

   g_timerDemo.Start();

   /////////////////
   // Spark Setup //
   /////////////////

#ifdef USE_SPARK
   SPK::System::setClampStep(true,0.1f);         // clamp the step to 100 ms
   SPK::System::useAdaptiveStep(0.001f,0.01f);      // use an adaptive step from 1ms to 10ms (1000fps to 100fps)

   g_pSystem = SPK::System::create(true);
   g_pSystem->enableAABBComputation(true);

   g_pPointRenderer = SPK::DX9::DX9PointRenderer::create();

   g_pQuadRenderer = SPK::DX9::DX9QuadRenderer::create(4.0f,4.0f);
   g_pQuadRenderer->setAtlasDimensions(1,1);
   g_pQuadRenderer->setBlendMode(SPK::BLEND_MODE_ADD);
   g_pQuadRenderer->enableRenderingOption(SPK::RENDERING_OPTION_DEPTH_WRITE,false);
   g_pQuadRenderer->setTexturingMode(SPK::TEXTURE_MODE_2D);
   g_pQuadRenderer->setTexture(textureParticle);
   //g_pLineTrailRenderer = SPK::DX9::DX9PointRenderer::create();
   g_pLineTrailRenderer = SPK::DX9::DX9LineTrailRenderer::create(2,0.65f);
   //lineTrailRenderer->setNbSamples(32);
   g_pLineTrailRenderer->setBlendMode(SPK::BLEND_MODE_ADD);
   g_pLineTrailRenderer->enableRenderingOption(SPK::RENDERING_OPTION_DEPTH_WRITE,false);

   g_pEmitter = SPK::RandomEmitter::create();
   g_pEmitter->setZone(SPK::Point::create());
   g_pEmitter->setForce(0.4f,0.6f);
   g_pEmitter->setFlow(50);

   g_pGravity = SPK::Gravity::create(SPK::Vector3D(0.0f,-0.5f,0.0f));
   g_pFriction = SPK::Friction::create(0.2f);

   g_pGraphInterpolator = SPK::ColorGraphInterpolator::create();
   g_pGraphInterpolator->addEntry(0.0f,0xFF000088);
   g_pGraphInterpolator->addEntry(0.5f,0x00FF0088);
   g_pGraphInterpolator->addEntry(1.0f,0x0000FF88);

   g_pObstacle = SPK::Obstacle::create(SPK::Plane::create(SPK::Vector3D(0.0f,-0.8f,0.0f),SPK::Vector3D(0.0f,1.0f,0.0f)));

   
   g_pGroup1 = g_pSystem->createGroup(100);
   g_pGroup1->setRadius(0.05f);
   g_pGroup1->setLifeTime(1.0f,2.0f);
   //group1->setColorInterpolator(SPK::ColorDefaultInitializer::create(0xFFFF2288));
   g_pGroup1->setColorInterpolator(g_pGraphInterpolator);
   g_pGroup1->setParamInterpolator(SPK::PARAM_SCALE,SPK::FloatRandomInterpolator::create(0.8f,1.2f,0.0f,0.0f));
   g_pGroup1->setParamInterpolator(SPK::PARAM_ROTATION_SPEED,SPK::FloatRandomInitializer::create(-2.0f,2.0f));
   g_pGroup1->setParamInterpolator(SPK::PARAM_ANGLE,SPK::FloatRandomInitializer::create(0.0f,2 * 3.14159f));
   g_pGroup1->addEmitter(g_pEmitter);
   g_pGroup1->addModifier(g_pGravity);
   g_pGroup1->addModifier(g_pFriction);
   g_pGroup1->addModifier(g_pObstacle);
   g_pGroup1->addModifier(SPK::Rotator::create());
   g_pGroup1->setRenderer(g_pQuadRenderer);
   
   
   g_pGroup2 = g_pSystem->createGroup(1000);
   g_pGroup2->setRadius(0.0f);
   g_pGroup2->setLifeTime(1.0f,1.0f);
   g_pGroup2->setColorInterpolator(SPK::ColorSimpleInterpolator::create(0xFF000088,0x0000FF00));
   g_pGroup2->addModifier(g_pGravity);
   g_pGroup2->addModifier(g_pFriction);
   g_pGroup2->addModifier(g_pObstacle);
   g_pGroup2->setRenderer(g_pLineTrailRenderer);
   g_pGroup2->addEmitter(SPK::RandomEmitter::create(SPK::Sphere::create(SPK::Vector3D(0,0,0),4.0f),true,-1,100,10.0f,40.0f));
   
   

   //g_pGroup1->setDeathAction(SPK::SpawnParticlesAction::create(5,10,1,g_pEmitter));

   //*
   //*/
#endif
}

void UnInit()
{
   SAFE_RELEASE( textureParticle );

   SAFE_RELEASE( g_pMesh );

   SAFE_DELETE( g_pCamera );
}

void Move()
{
   g_pCamera->Move();
   float deltaTime = float(g_timerDemo.GetElapsedTime());

#ifdef USE_SPARK
   g_pSystem->updateParticles(deltaTime);
#endif
}

void Draw()
{
   g_pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f), 1.0f, 0 );

   g_pD3DDevice->SetTransform(D3DTS_PROJECTION, &g_pCamera->m_mProj);
   g_pD3DDevice->SetTransform(D3DTS_VIEW, &g_pCamera->m_mView);

   //*
   //g_pD3DDevice->SetLight(0,&g_light);
   g_pD3DDevice->LightEnable(0, false);
    g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, false);
   g_pD3DDevice->SetRenderState(D3DRS_SPECULARENABLE, TRUE);
   //*/
   g_pD3DDevice->SetRenderState(D3DRS_COLORVERTEX, true);

   //              g_pD3DDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_COLORVALUE( 0.8f, 0.8f, 0.8f, 1.0f ));

   g_pD3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, false);

   g_pD3DDevice->SetRenderState(D3DRS_COLORVERTEX, true);

   g_pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

   g_pD3DDevice->BeginScene();

   //g_pD3DDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
   //g_pMesh->DrawSubset(0);
#ifdef USE_SPARK
   g_pSystem->renderParticles();
#endif

   g_pD3DDevice->EndScene();
   g_pD3DDevice->Present( NULL, NULL, NULL, NULL );
}

int Run()
{
   MSG uMsg;
    ZeroMemory(&uMsg, sizeof(uMsg));

   while( uMsg.message != WM_QUIT )
   {
      //if( GetMessage( &uMsg, NULL, 0, 0 ) )
      if( PeekMessage( &uMsg, NULL, 0, 0, PM_REMOVE ) )
      {
         TranslateMessage( &uMsg );
         DispatchMessage( &uMsg );
      }
        else
      {
         Move();
         Draw();
      }
   }

   UnInit();

   SAFE_RELEASE( g_pD3DDevice );
   SAFE_RELEASE( g_pD3D );
   UnregisterClass("SPARKDemoBasicDX9", g_hInst);

   system("PAUSE");

   FreeConsole();

   return int(uMsg.wParam);
}

void InitializeConsoleStdIO()
{
    // si une console est rattachée au processus, alors il existe des fichiers
    // virtuel CONIN$ et CONOUT$ qui permettent respectivement de lire
    // et d'écrire depuis / dans cette console (voir la doc de CreateFile).

#if _MSC_VER >= 1400 // VC++ 8
    {
    // éviter le warning C4996: 'freopen' was declared deprecated
    // This function or variable may be unsafe. Consider using freopen_s instead.
    FILE *stream;
    freopen_s( &stream, "CONIN$", "r", stdin );
    freopen_s( &stream, "CONOUT$", "w", stdout );
    freopen_s( &stream, "CONOUT$", "w", stderr );
    }
#else
    std::freopen( "CONIN$", "r", stdin );
    std::freopen( "CONOUT$", "w", stdout );
    std::freopen( "CONOUT$", "w", stderr );
#endif

    // la ligne suivante synchronise les flux standards C++ (cin, cout, cerr...)
    std::ios_base::sync_with_stdio();
}

// Main function
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
   ::AllocConsole();
   InitializeConsoleStdIO();

#if defined(DEBUG) | defined(_DEBUG)
   _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
   //_CrtSetBreakAlloc(160);

   screenHeight = 600;
   CreateWnd(hInstance, 800, 600);
   InitDX(800, 600, false);
   Init();
   return Run();
}

LRESULT CALLBACK MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   switch( uMsg )
   {
      case WM_KEYDOWN:
         switch( wParam )
         {
            case VK_ESCAPE:
               PostQuitMessage(0);
               break;
            case VK_F4:
               cout << "buffers destroyed" << endl;
               g_pGroup1->destroyRenderBuffer();
               g_pGroup2->destroyRenderBuffer();
               break;

            default:
               break;
         }
         break;

      case WM_RBUTTONDOWN:
         g_bSourisDroite = true;
         break;

      case WM_MOUSEMOVE:
         {
            // déplacement relatif
            int   px = GET_X_LPARAM(lParam);
            int   py = GET_Y_LPARAM(lParam);
            
            float dx = (px - g_ptSourisPosition.x)/5.f;
            float dy = (py - g_ptSourisPosition.y)/5.f;
            g_ptSourisPosition.x = px;
            g_ptSourisPosition.y = py;
            if ( g_bSourisDroite  )
            {
               g_pCamera->m_fAngleH += -dx;
               g_pCamera->m_fAngleV += dy;
            }
         }
         break;

      case WM_RBUTTONUP: g_bSourisDroite = false; break;

      case WM_MOUSEWHEEL:
         {
            if( typeid(*g_pCamera) == typeid(CGlobalCamera) )
            {
               g_pCamera->m_fDistance += float(GET_WHEEL_DELTA_WPARAM(wParam)) / 200.0f;
               if( g_pCamera->m_fDistance < 0.2f ) g_pCamera->m_fDistance = 0.2f;
            }
         }
         break;

      case WM_DESTROY:
            PostQuitMessage(0);
         break;
      
        default:
            // The DefWindowProc() function will process any messages that
            // we didn't bother to catch in the switch statement above.
            return DefWindowProc( hWnd, uMsg, wParam, lParam );
    }
   return 0;
}
Back to top Go down
stardeath
Committer



Messages : 140
Date d'inscription : 2009-08-24

[SPARK 2] Bug Report Empty
PostSubject: Re: [SPARK 2] Bug Report   [SPARK 2] Bug Report Icon_minitimeWed Nov 09, 2011 1:10 pm

i found the bug, i forgot to reset texture at stage 0 after the rendering, i will commit the fix after some tests.

edit : fix commited.
Back to top Go down
shd




Messages : 4
Date d'inscription : 2011-12-06

[SPARK 2] Bug Report Empty
PostSubject: cmake and crossplatform   [SPARK 2] Bug Report Icon_minitimeTue Dec 06, 2011 9:05 pm

Hey,
Firstly, thanks for great particle engine, which i'd like to use in my game.

There are few issues though,
1) Could you define options in CMake to compile irrlicht, dx, (and probably GL) separately?
I'm not using irrlicht nor DX (especially on Linux), so i have to comment them by hand. I think it would help people completely not familiar with CMake to actually compile it with this system.

2) First issue was rather trivial. This one (probably) won't be so. Because I'm normally not coding in C++ anymore, i might be missing something so please correct me if i'm wrong. There is a problem with compilation on compilers other than Visual C++. I have no time to look into this more deeply (as i'm not usual C++ programmer it probably won't be a fast activity). The thing is, I've tried to compile SPARK2 with g++ and clang both, but it failed while on MS Windows + MS compiler it worked great, Firstly, CMake scripts are lacking of c++x0 flags. GCC is complaining about functions forward declarations (which AFAIK isn't allowed by standards), and CLANG 2.9 is failing generally. It's probably something with my set-up, and i'll wait for OS packages upgrade, or just wait for some time to test it further with clang, but i think spark2 should be working on g++ anyway. It isn't possible though without some refactoring (if i'm not wrong), because there are cyclic declaration-dependencies.

Edit: Oh, forgot about this one. Could you please do not use '>>' for closing nested templates, but '> >' for gcc compatibility?
Edit2: You would also have to add 'var.template cast' instead of 'var.cast'
Back to top Go down
stardeath
Committer



Messages : 140
Date d'inscription : 2009-08-24

[SPARK 2] Bug Report Empty
PostSubject: Re: [SPARK 2] Bug Report   [SPARK 2] Bug Report Icon_minitimeWed Dec 07, 2011 6:20 pm

personally i don't use gcc, because of that, i can't change my coding style so easily.

this aside, it's more a problem with gcc which can't understand ">>" for closing template.

my speech helps nobody but i think i should say it.
Back to top Go down
shd




Messages : 4
Date d'inscription : 2011-12-06

[SPARK 2] Bug Report Empty
PostSubject: Re: [SPARK 2] Bug Report   [SPARK 2] Bug Report Icon_minitimeWed Dec 07, 2011 6:48 pm

stardeath wrote:
personally i don't use gcc, because of that, i can't change my coding style so easily.

this aside, it's more a problem with gcc which can't understand ">>" for closing template.

my speech helps nobody but i think i should say it.
I understand that, and appreciate your answer. You should consider though explicit specializations in namespace scope, or more generally, try to stick with standard, because it might be useful to you sometime in future if you would have to work with non-visual C++ compilers (and now for i.e. me). Visual C++ is quite permissive which can be considered as advantage, but standard compliance is still a good thing.
This would help me to maintain my fork which would follow the trunk, and keep g++ compliant version.
Back to top Go down
stardeath
Committer



Messages : 140
Date d'inscription : 2009-08-24

[SPARK 2] Bug Report Empty
PostSubject: Re: [SPARK 2] Bug Report   [SPARK 2] Bug Report Icon_minitimeWed Dec 07, 2011 7:48 pm

my bad, i didn't know it is in the c++98 standard, as far as i remember, i never write "> >" even with "old" vs version (2008).

i will try to correct myself, but i can't promise XD
Back to top Go down
Darktib
Committer
Darktib


Messages : 389
Date d'inscription : 2009-07-20
Localisation : A coté de Paris

[SPARK 2] Bug Report Empty
PostSubject: Re: [SPARK 2] Bug Report   [SPARK 2] Bug Report Icon_minitimeThu Dec 08, 2011 4:03 am

Hello,

shd wrote:
1) Could you define options in CMake to compile irrlicht, dx, (and probably GL) separately?
I'm not using irrlicht nor DX (especially on Linux), so i have to comment them by hand. I think it would help people completely not familiar with CMake to actually compile it with this system.
I don't understand: it is already the case.
Which tool chain do you use ? Code::Blocks ? Makefiles ?
For the engine CMake project: when configuring, some errors about Irrlicht can occur, but you can safely ignore them if you're not using Irrlicht. Then generate the project. Normally, it should generates a solution with several projects, and you can choose the one to compile in and IDE like Visual Studio or Code::Blocks. For the moment, this is the only way if you want to have dependency checking.
If you want to build just a project, you can go in "%SPARK2DIR%/projects/engine/projectname" where "projectname" is the name of the project you want to build, for example "core" or "ogl". You will have to check the dependecies by yourself, however the only dependencies of non-Irrlicht and non-DX projects are glew (for OGL) and pugixml (for core) (and core for other projects Wink ).

I think I will put some checking code to avoid false warnings when not using Irrlicht.


Back to top Go down
shd




Messages : 4
Date d'inscription : 2011-12-06

[SPARK 2] Bug Report Empty
PostSubject: Re: [SPARK 2] Bug Report   [SPARK 2] Bug Report Icon_minitimeThu Dec 08, 2011 7:13 pm

Darktib wrote:

Which tool chain do you use ? Code::Blocks ? Makefiles ?
CMake -> Unix Makefiles OR NMake Makefiles -> SWIG

Quote :

For the engine CMake project: when configuring, some errors about Irrlicht can occur, but you can safely ignore them if you're not using Irrlicht.
Oh. uh. I didn't even checked if project is buildable - my bad. When i noticed these errors i just commented out 4 lines with irr and dx modules and everything went fine. Don't get me wrong, i don't find it a big problem. It was just a small note, that you could define something like SPARK_WITH_IRR(enabled by default) SPARK_WITH_DX (on !Windows disabled by default) and then find_package(Irrlicht) etc.

The main reason why i was writing this post was non-Visual C++ compatibility which is quite problematic for me, but you are developers here, so you're the boss.
Back to top Go down
Darktib
Committer
Darktib


Messages : 389
Date d'inscription : 2009-07-20
Localisation : A coté de Paris

[SPARK 2] Bug Report Empty
PostSubject: Re: [SPARK 2] Bug Report   [SPARK 2] Bug Report Icon_minitimeFri Dec 09, 2011 2:40 pm

shd wrote:
i don't find it a big problem
Nice to read this!
shd wrote:
was just a small note, that you could define something like SPARK_WITH_IRR(enabled by default) SPARK_WITH_DX (on !Windows disabled by default) and then find_package(Irrlicht) etc.
That is planned. I am just search for an elegant way to do that. I think it could be on the svn next week.
Back to top Go down
MonRoyal




Messages : 6
Date d'inscription : 2011-11-17

[SPARK 2] Bug Report Empty
PostSubject: Bug in killing particles   [SPARK 2] Bug Report Icon_minitimeWed Dec 14, 2011 10:21 am

Hi,

when I kill a particle his energy is set to 0. In the Group::updateParticles the energy is recomputed before the life time check takes place:

particleData.energies[i] = 1.0f - particleData.ages[i] / particleData.lifeTimes[i];

So the previous setting to 0 has no effect, because the age is taken into consideration.

Hope it's clear Smile
Back to top Go down
Juff
Developer



Messages : 539
Date d'inscription : 2009-07-14
Age : 41

[SPARK 2] Bug Report Empty
PostSubject: Re: [SPARK 2] Bug Report   [SPARK 2] Bug Report Icon_minitimeWed Dec 14, 2011 4:07 pm

Yep its because particle.kill() was meant to be called within a modifier
Anyway I now set the age to be the lifetime when killing the particle so it should work
Back to top Go down
http://spark.developpez.com
Sponsored content





[SPARK 2] Bug Report Empty
PostSubject: Re: [SPARK 2] Bug Report   [SPARK 2] Bug Report Icon_minitime

Back to top Go down
 
[SPARK 2] Bug Report
Back to top 
Page 1 of 3Go to page : 1, 2, 3  Next
 Similar topics
-
» Bug Report and CMake
» SPARK and C++
» Spark opengl 64 bit
» OpenSceneGraph (OSG) and Spark
» Using SPARK with SFML

Permissions in this forum:You cannot reply to topics in this forum
 :: English Forum :: Evolution (en)-
Jump to: