mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-09-08 06:50:46 +02:00
Fix TPTScript 'set' function
This commit is contained in:
@@ -194,6 +194,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
|||||||
AnyType value = eval(words);
|
AnyType value = eval(words);
|
||||||
|
|
||||||
Simulation * sim = m->GetSimulation();
|
Simulation * sim = m->GetSimulation();
|
||||||
|
unsigned char * partsBlock = (unsigned char*)&sim->parts[0];
|
||||||
|
|
||||||
int returnValue = 0;
|
int returnValue = 0;
|
||||||
|
|
||||||
@@ -205,10 +206,10 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
|||||||
|
|
||||||
//Selector
|
//Selector
|
||||||
int newValue;
|
int newValue;
|
||||||
if(selector.GetType() == TypeNumber)
|
if(value.GetType() == TypeNumber)
|
||||||
newValue = ((NumberType)selector).Value();
|
newValue = ((NumberType)value).Value();
|
||||||
else if(selector.GetType() == TypeString)
|
else if(value.GetType() == TypeString)
|
||||||
newValue = GetParticleType(((StringType)selector).Value());
|
newValue = GetParticleType(((StringType)value).Value());
|
||||||
else
|
else
|
||||||
throw GeneralException("Invalid value for assignment");
|
throw GeneralException("Invalid value for assignment");
|
||||||
|
|
||||||
@@ -230,10 +231,10 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
|||||||
switch(propertyFormat)
|
switch(propertyFormat)
|
||||||
{
|
{
|
||||||
case FormatInt:
|
case FormatInt:
|
||||||
*((int*)(((unsigned char*)&sim->parts[partIndex])+propertyOffset)) = newValue;
|
*((int*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValue;
|
||||||
break;
|
break;
|
||||||
case FormatFloat:
|
case FormatFloat:
|
||||||
*((float*)(((unsigned char*)&sim->parts[partIndex])+propertyOffset)) = newValue;
|
*((float*)(partsBlock+(partIndex*sizeof(Particle))+propertyOffset)) = newValue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
returnValue = 1;
|
returnValue = 1;
|
||||||
@@ -248,7 +249,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
|||||||
if(sim->parts[j].type)
|
if(sim->parts[j].type)
|
||||||
{
|
{
|
||||||
returnValue++;
|
returnValue++;
|
||||||
*((int*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = newValue;
|
*((int*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -258,7 +259,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
|||||||
if(sim->parts[j].type)
|
if(sim->parts[j].type)
|
||||||
{
|
{
|
||||||
returnValue++;
|
returnValue++;
|
||||||
*((float*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = newValue;
|
*((float*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -274,6 +275,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
|||||||
|
|
||||||
if(type<0 || type>=PT_NUM)
|
if(type<0 || type>=PT_NUM)
|
||||||
throw GeneralException("Invalid particle type");
|
throw GeneralException("Invalid particle type");
|
||||||
|
std::cout << propertyOffset << std::endl;
|
||||||
switch(propertyFormat)
|
switch(propertyFormat)
|
||||||
{
|
{
|
||||||
case FormatInt:
|
case FormatInt:
|
||||||
@@ -282,7 +284,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
|||||||
if(sim->parts[j].type == type)
|
if(sim->parts[j].type == type)
|
||||||
{
|
{
|
||||||
returnValue++;
|
returnValue++;
|
||||||
*((int*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = newValue;
|
*((int*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -292,7 +294,7 @@ AnyType TPTScriptInterface::tptS_set(std::deque<std::string> * words)
|
|||||||
if(sim->parts[j].type == type)
|
if(sim->parts[j].type == type)
|
||||||
{
|
{
|
||||||
returnValue++;
|
returnValue++;
|
||||||
*((float*)(((unsigned char*)&sim->parts[j])+propertyOffset)) = newValue;
|
*((float*)(partsBlock+(j*sizeof(Particle))+propertyOffset)) = newValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user