Merge with hotfix

This commit is contained in:
kaetemi 2014-12-22 16:40:12 +01:00
commit 5190cbf8ff
35 changed files with 743 additions and 1723 deletions

View file

@ -627,9 +627,11 @@ bool CDriverGL::setDisplay(nlWindow wnd, const GfxMode &mode, bool show, bool re
// Offscreen mode ?
if (_CurrentMode.OffScreen)
{
#if 0
if (!createWindow(mode))
return false;
HWND tmpHWND = _win;
int width = mode.Width;
int height = mode.Height;
// resize the window
RECT rc;
@ -908,7 +910,6 @@ bool CDriverGL::setDisplay(nlWindow wnd, const GfxMode &mode, bool show, bool re
_hDC = NULL;
return false;
}
#endif
}
else
{
@ -1437,8 +1438,17 @@ bool CDriverGL::createWindow(const GfxMode &mode)
#ifdef NL_OS_WINDOWS
// create the OpenGL window
window = CreateWindowW(L"NLClass", L"NeL Window", WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
CW_USEDEFAULT, CW_USEDEFAULT, mode.Width, mode.Height, HWND_DESKTOP, NULL, GetModuleHandle(NULL), NULL);
DWORD dwStyle = WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
int pos = CW_USEDEFAULT;
HWND hwndParent = HWND_DESKTOP;
if (mode.OffScreen)
{
dwStyle &= ~WS_VISIBLE;
pos = 0;
hwndParent = NULL;
}
window = CreateWindowW(L"NLClass", L"NeL Window", dwStyle,
pos, pos, mode.Width, mode.Height, hwndParent, NULL, GetModuleHandle(NULL), NULL);
if (window == EmptyWindow)
{

View file

@ -1739,14 +1739,14 @@ bool MakeSnapShot (NLMISC::CBitmap &snapshot, const NL3D::CTileBank &tileBank, c
float posY = config.CellSize * (float)ymin;
// Use NELU
if (CNELU::init (oversampledWidth, oversampledHeight, CViewport(), 32, true, NULL, true))
if (CNELU::init (oversampledWidth, oversampledHeight, CViewport(), 32, true, NULL, false, true)) // FIXME: OpenGL not working correctly, offscreen not available in Direct3D
{
// Setup the camera
CNELU::Camera->setTransformMode (ITransformable::DirectMatrix);
CMatrix view;
view.setPos (CVector (width/2 + posX, height/2 + posY, width));
view.setRot (CVector::I, -CVector::K, CVector::J);
CNELU::Camera->setFrustum (width, height, 0.1f, 1000.f, false);
CNELU::Camera->setFrustum (width, height, 0.1f, 10000.f, false);
CNELU::Camera->setMatrix (view);
// Create a Landscape.
@ -1766,12 +1766,17 @@ bool MakeSnapShot (NLMISC::CBitmap &snapshot, const NL3D::CTileBank &tileBank, c
theLand->enableAdditive (true);
theLand->Landscape.setRefineMode (true);
// theLand->Landscape.setupStaticLight(CRGBA(255, 255, 255), CRGBA(0, 0, 0), 1.0f);
// theLand->Landscape.setThreshold(0.0005);
// Enbable automatique lighting
#ifndef NL_DEBUG
theLand->Landscape.enableAutomaticLighting (true);
theLand->Landscape.setupAutomaticLightDir (CVector (0, 0, -1));
// theLand->Landscape.enableAutomaticLighting (true);
// theLand->Landscape.setupAutomaticLightDir (CVector (0, 0, -1));
#endif // NL_DEBUG
// theLand->Landscape.updateLightingAll();
// Clear the backbuffer and the alpha
CNELU::clearBuffers(CRGBA(255,0,255,0));
@ -1851,7 +1856,7 @@ bool MakeSnapShot (NLMISC::CBitmap &snapshot, const NL3D::CTileBank &tileBank, c
Value* make_snapshot_cf (Value** arg_list, int count)
{
// Make sure we have the correct number of arguments (7)
check_arg_count(check_zone_with_template, 7, count);
check_arg_count(NeLLigoMakeSnapShot, 7, count);
// Check to see if the arguments match up to what we expect
char *message = "NeLLigoMakeSnapShot [Object] [Snapshot filename] [xMin] [xMax] [yMin] [yMax] [Error in dialog]";
@ -1903,11 +1908,11 @@ Value* make_snapshot_cf (Value** arg_list, int count)
else
{
// Build a filename
char drive[512];
char path[512];
char name[512];
char ext[512];
_splitpath (fileName.c_str(), drive, path, name, ext);
char drivetga[512];
char pathtga[512];
char nametga[512];
char exttga[512];
_splitpath (fileName.c_str(), drivetga, pathtga, nametga, exttga);
// Build the zone
CZone zone;
@ -1970,7 +1975,7 @@ Value* make_snapshot_cf (Value** arg_list, int count)
{
// Build the snap shot filename
char outputFilenameSnapShot[512];
_makepath (outputFilenameSnapShot, drive, path, name, ".tga");
_makepath (outputFilenameSnapShot, drivetga, pathtga, nametga, ".tga");
// Output the snap shot
COFile outputSnapShot;
@ -2011,10 +2016,10 @@ Value* make_snapshot_cf (Value** arg_list, int count)
// Write the zone
COFile outputLigoZone;
_makepath (outputFilenameSnapShot, drive, path, name, ".ligozone");
_makepath (outputFilenameSnapShot, drivetga, pathtga, nametga, ".ligozone");
// Catch exception
try
/*try
{
// Open the selected zone file
if (outputLigoZone.open (outputFilenameSnapShot))
@ -2043,7 +2048,7 @@ Value* make_snapshot_cf (Value** arg_list, int count)
char tmp[512];
smprintf (tmp, 512, "Error while loading the file %s : %s", fileName, e.what());
CMaxToLigo::errorMessage (tmp, "NeL Ligo export zone", *MAXScript_interface, errorInDialog);
}
}*/
}
else
{

View file

@ -338,6 +338,8 @@ get_selected_tile_cf(Value** arg_list, int count)
if (tri->rpatch->tileSel[i])
array->append(Integer::intern(i+1));
}
if (os.obj != tri)
delete tri;
}
}
@ -383,6 +385,8 @@ get_selected_patch_cf(Value** arg_list, int count)
if (tri->patch.patchSel[i])
array->append(Integer::intern(i+1));
}
if (os.obj != tri)
delete tri;
}
}
@ -428,6 +432,8 @@ get_selected_vertex_cf(Value** arg_list, int count)
if (tri->patch.vertSel[i])
array->append(Integer::intern(i+1));
}
if (os.obj != tri)
delete tri;
}
}
@ -617,6 +623,8 @@ set_vertex_count_cf(Value** arg_list, int count)
{
nRet=tri->patch.numVerts;
}
if (os.obj != tri)
delete tri;
}
return Integer::intern(nRet);
@ -655,6 +663,8 @@ set_vector_count_cf(Value** arg_list, int count)
{
nRet=tri->patch.numVecs;
}
if (os.obj != tri)
delete tri;
}
return Integer::intern(nRet);
@ -702,6 +712,8 @@ set_vertex_pos_cf(Value** arg_list, int count)
node->NotifyDependents(FOREVER, PART_ALL, REFMSG_CHANGE);
ip->RedrawViews(ip->GetTime());
}
if (os.obj != tri)
delete tri;
}
}
@ -750,6 +762,8 @@ set_vector_pos_cf(Value** arg_list, int count)
node->NotifyDependents(FOREVER, PART_ALL, REFMSG_CHANGE);
ip->RedrawViews(ip->GetTime());
}
if (os.obj != tri)
delete tri;
}
}
@ -792,6 +806,8 @@ get_vertex_pos_cf(Value** arg_list, int count)
{
vRet=new Point3Value (tri->patch.verts[nVertex].p);
}
if (os.obj != tri)
delete tri;
}
}
@ -834,6 +850,8 @@ get_vector_pos_cf(Value** arg_list, int count)
{
vRet=new Point3Value (tri->patch.vecs[nVertex].p);
}
if (os.obj != tri)
delete tri;
}
}
@ -877,6 +895,8 @@ get_edge_vect1_cf(Value** arg_list, int count)
{
nVert=tri->patch.edges[nEdge].vec12;
}
if (os.obj != tri)
delete tri;
}
}
@ -919,6 +939,8 @@ get_edge_vect2_cf(Value** arg_list, int count)
{
nVert=tri->patch.edges[nEdge].vec21;
}
if (os.obj != tri)
delete tri;
}
}
@ -961,6 +983,8 @@ get_edge_vert1_cf(Value** arg_list, int count)
{
nVert=tri->patch.edges[nEdge].v1;
}
if (os.obj != tri)
delete tri;
}
}
@ -1004,6 +1028,8 @@ get_edge_vert2_cf(Value** arg_list, int count)
{
nVert=tri->patch.edges[nEdge].v2;
}
if (os.obj != tri)
delete tri;
}
}
@ -1050,6 +1076,8 @@ get_sel_edge_cf(Value** arg_list, int count)
array->append(Integer::intern(i+1));
//array->data[j++]=;
}
if (os.obj != tri)
delete tri;
}
}
@ -1158,6 +1186,8 @@ set_tile_steps_cf(Value** arg_list, int count)
nTess=5;
tri->rpatch->rTess.TileTesselLevel=nTess;
tri->rpatch->InvalidateChannels (PART_ALL);
if (os.obj != tri)
delete tri;
}
if (bRet)
{

View file

@ -755,6 +755,7 @@ class EditPatchMod : public Modifier, IPatchOps, IPatchSelect, ISubMtlAPI, Attac
TCHAR *GetObjectName() { return GetString(IDS_TH_EDITPATCH); }
void ActivateSubobjSel(int level, XFormModes& modes );
int NeedUseSubselButton() { return 0; }
void SelectSubPatch(int index);
void SelectSubComponent( HitRecord *hitRec, BOOL selected, BOOL all, BOOL invert );
void ClearSelection(int selLevel);
void SelectAll(int selLevel);

View file

@ -84,6 +84,31 @@
*> Copyright(c) 1994, All Rights Reserved.
**********************************************************************/
#include "stdafx.h"
#if MAX_VERSION_MAJOR >= 14
# include <maxscript/maxscript.h>
# include <maxscript/foundation/3dmath.h>
# include <maxscript/foundation/numbers.h>
# include <maxscript/maxwrapper/maxclasses.h>
# include <maxscript/foundation/streams.h>
# include <maxscript/foundation/mxstime.h>
# include <maxscript/maxwrapper/mxsobjects.h>
# include <maxscript/compiler/parser.h>
# include <maxscript/macros/define_instantiation_functions.h>
#else
# include <MaxScrpt/maxscrpt.h>
# include <MaxScrpt/3dmath.h>
// Various MAX and MXS includes
# include <MaxScrpt/Numbers.h>
# include <MaxScrpt/MAXclses.h>
# include <MaxScrpt/Streams.h>
# include <MaxScrpt/MSTime.h>
# include <MaxScrpt/MAXObj.h>
# include <MaxScrpt/Parser.h>
// define the new primitives using macros from SDK
# include <MaxScrpt/definsfn.h>
#endif
#include "editpat.h"
#include "../nel_patch_lib/vertex_neighborhood.h"
@ -855,3 +880,67 @@ void ResetVert (PatchMesh *patch)
patch->computeInteriors();
patch->InvalidateGeomCache ();
}
def_visible_primitive(turn_patch, "RykolTurnPatch");
Value *turn_patch_cf (Value** arg_list, int count)
{
// Make sure we have the correct number of arguments (2)
check_arg_count(RykolTurnPatch, 3, count);
// Check to see if the arguments match up to what we expect
// We want to use 'TurnAllTexturesOn <object to use>'
type_check(arg_list[0], MAXNode, "RykolTurnPatch [Node] [Modifier] [Patch]");
type_check(arg_list[1], MAXModifier, "RykolTurnPatch [Node] [Modifier] [Patch]");
type_check(arg_list[2], Integer, "RykolTurnPatch [Node] [Modifier] [Patch]");
// Get a good interface pointer
Interface *ip = MAXScript_interface;
// Get a INode pointer from the argument passed to us
INode *node = arg_list[0]->to_node();
nlassert (node);
// Get a Object pointer
ObjectState os = node->EvalWorldState(ip->GetTime());
// ok ?
bool bRet=false;
if (os.obj)
{
// Get class id
if (os.obj->CanConvertToType(RYKOLPATCHOBJ_CLASS_ID))
{
bRet = true;
RPO *tri = (RPO *)os.obj->ConvertToType(ip->GetTime(), RYKOLPATCHOBJ_CLASS_ID);
if (tri)
{
Modifier *mod = arg_list[1]->to_modifier();
if (mod)
{
EditPatchMod *epmod = (EditPatchMod *)mod;
epmod->ClearSelection(EP_PATCH);
epmod->SelectSubPatch(arg_list[2]->to_int() - 1);
epmod->DoPatchTurn(true);
epmod->ClearSelection(EP_PATCH);
}
else
{
bRet = false;
}
}
// Note that the TriObject should only be deleted
// if the pointer to it is not equal to the object
// pointer that called ConvertToType()
if (os.obj != tri)
delete tri;
// redraw and update
node->NotifyDependents(FOREVER, PART_ALL, REFMSG_CHANGE);
ip->RedrawViews(ip->GetTime());
}
}
return bRet?&true_value:&false_value;
}

View file

@ -236,6 +236,50 @@ void EditPatchMod::SetSelLevel(DWORD level)
// ------------------------------------------------------------------------------------------------------------------------------------------------------
void EditPatchMod::SelectSubPatch(int index)
{
if (!ip)
return;
TimeValue t = ip->GetTime();
ip->ClearCurNamedSelSet();
ModContextList mcList;
INodeTab nodes;
ip->GetModContexts(mcList, nodes);
for (int i = 0; i < mcList.Count(); i++)
{
EditPatchData *patchData =(EditPatchData*)mcList[i]->localData;
if (!patchData)
return;
RPatchMesh *rpatch;
PatchMesh *patch = patchData->TempData(this)->GetPatch(t, rpatch);
if (!patch)
return;
patchData->BeginEdit(t);
if (theHold.Holding())
theHold.Put(new PatchRestore(patchData, this, patch, rpatch, "SelectSubComponent"));
patch->patchSel.Set(index);
patchData->UpdateChanges(patch, rpatch, FALSE);
if (patchData->tempData)
{
patchData->tempData->Invalidate(PART_SELECT);
}
}
PatchSelChanged();
UpdateSelectDisplay();
NotifyDependents(FOREVER, PART_SELECT, REFMSG_CHANGE);
}
// ------------------------------------------------------------------------------------------------------------------------------------------------------
// Select a subcomponent within our object(s). WARNING! Because the HitRecord list can
// indicate any of the objects contained within the group of patches being edited, we need
// to watch for control breaks in the patchData pointer within the HitRecord!

View file

@ -176,6 +176,7 @@ LockBorders = KeyL;
ZoomIn = Key1;
ZoomOut = Key2;
GetState = Key3;
ResetPatch = KeyF10;
/***************
*This is the the light settings

View file

@ -145,7 +145,7 @@ std::vector<CZoneSymmetrisation> symVector;
// Painter modes
enum TModePaint { ModeTile, ModeColor, ModeDisplace};
enum TModeMouse { ModePaint, ModeSelect, ModePick, ModeFill, ModeGetState };
enum TModeMouse { ModePaint, ModeSelect, ModePick, ModeFill, ModeGetState, ModeResetPatch };
/*-------------------------------------------------------------------*/
@ -2585,6 +2585,13 @@ void mainproc(CScene& scene, CEventListenerAsync& AsyncListener, CEvent3dMouseLi
// Set mode
modeSelect=ModeGetState;
// Mode reset zone
if (AsyncListener.isKeyDown ((TKey)PainterKeys[ResetPatch]))
{
// Set mode
modeSelect=ModeResetPatch;
}
// Mode picking
if (AsyncListener.isKeyDown ((TKey)PainterKeys[Fill0]))
{
@ -2891,6 +2898,8 @@ void mainproc(CScene& scene, CEventListenerAsync& AsyncListener, CEvent3dMouseLi
SetCursor (bankCont->HFill);
else if (pData->pobj->TileTrick)
SetCursor (bankCont->HTrick);
else if (modeSelect==ModeResetPatch)
SetCursor (LoadCursor (NULL, IDC_NO));
else
SetCursor (LoadCursor (NULL, IDC_ARROW));
@ -3034,7 +3043,7 @@ private:
// Callback on mouse events
virtual void operator ()(const CEvent& event)
{
if (event==EventDestroyWindowId)
if (event==EventDestroyWindowId || event==EventCloseWindowId)
{
WindowActive=false;
}
@ -3140,9 +3149,30 @@ private:
_FillTile.fillColor (mesh1, patch, _VectMesh, maxToNel (color1), (uint16)(256.f*opa1), PaintColor);
else if (nModeTexture==ModeDisplace)
// Fill this patch with the current color
// Fill this patch with the current displace
_FillTile.fillDisplace (mesh1, patch, _VectMesh, bank);
}
else if (modeSelect==ModeResetPatch)
{
int np = _VectMesh[mesh1].PMesh->numPatches;
for (int pp = 0; pp < np; ++pp)
{
// Fill default tile
_FillTile.fillTile (mesh1, pp, _VectMesh, -1, 0, 0, true, bank);
// Fill default color
_FillTile.fillColor (mesh1, pp, _VectMesh, CRGBA(255, 255, 255), 256, PaintColor);
// Backup current displace, fill default, restore
int bkdt = _Pobj->DisplaceTile;
int bkdts = _Pobj->DisplaceTileSet;
_Pobj->DisplaceTile = 0;
_Pobj->DisplaceTileSet = -1;
_FillTile.fillDisplace (mesh1, pp, _VectMesh, bank);
_Pobj->DisplaceTile = bkdt;
_Pobj->DisplaceTileSet = bkdts;
}
}
}
}
// Pick with right mouse
@ -4095,7 +4125,7 @@ DWORD WINAPI myThread (LPVOID vData)
// Create a Landscape.
CLandscapeModel *TheLand= (CLandscapeModel*)CNELU::Scene->createModel(LandscapeModelId);
TheLand->Landscape.setTileNear (1000.f);
TheLand->Landscape.setTileNear (10000.f);
TheLand->Landscape.TileBank=bank;
// Enbable automatique lighting
@ -4192,7 +4222,7 @@ DWORD WINAPI myThread (LPVOID vData)
mat.setPos(P);
CNELU::Camera->setTransformMode (ITransformable::DirectMatrix);
CNELU::Camera->setMatrix (mat);
CNELU::Camera->setPerspective( 75.f*(float)Pi/180.f/*vp->GetFOV()*/, 1.33f, 0.1f, 1000.f);
CNELU::Camera->setPerspective( 75.f*(float)Pi/180.f/*vp->GetFOV()*/, 1.33f, 0.1f, 10000.f);
// Resize the sym vector
symVector.resize (pData->VectMesh.size());
@ -4257,6 +4287,7 @@ DWORD WINAPI myThread (LPVOID vData)
CNELU::EventServer.addListener (EventMouseUpId, &listener);
CNELU::EventServer.addListener (EventMouseDblClkId, &listener);
CNELU::EventServer.addListener (EventDestroyWindowId, &listener);
CNELU::EventServer.addListener (EventCloseWindowId, &listener);
CNELU::EventServer.addListener (EventKeyDownId, &listener);
// Camera position
@ -4326,6 +4357,7 @@ DWORD WINAPI myThread (LPVOID vData)
CNELU::EventServer.removeListener (EventMouseDblClkId, &listener);
CNELU::EventServer.removeListener (EventKeyDownId, &listener);
CNELU::EventServer.removeListener (EventDestroyWindowId, &listener);
CNELU::EventServer.removeListener (EventCloseWindowId, &listener);
// End.
//========

View file

@ -43,6 +43,7 @@ uint PainterKeys[KeyCounter]=
Key1,
Key2,
KeyI,
KeyF10,
};
// Keys
@ -77,6 +78,7 @@ const char* PainterKeysName[KeyCounter]=
"ZoomIn",
"ZoomOut",
"GetState",
"ResetPatch",
};
// Light settings

View file

@ -122,6 +122,7 @@ enum PainterKeysType
ZoomIn,
ZoomOut,
GetState,
ResetPatch,
KeyCounter
};

View file

@ -0,0 +1,124 @@
gc()
nodes = getCurrentSelection()
max select none
clearselection()
undo off
(
for cnode in nodes do
(
if (classof cnode) == Editable_Patch or (classof cnode) == RklPatch then
(
print cnode.name
selectmore cnode
if (classof cnode) == Editable_Patch and (classof cnode) != RklPatch then
(
modPanel.addModToSelection (NeL_Convert ()) ui:on
)
modPanel.addModToSelection (NeL_Edit ()) ui:on
setCommandPanelTaskMode #modify
cmod = modpanel.getCurrentObject()
pcount = (GetRykolPatchCount cnode)
print pcount
for p = 1 to pcount do
(
--print p
vbegin = (NeLGetPatchVertex cnode p 1)
vend = (NeLGetPatchVertex cnode p 2)
vref = (NeLGetPatchVertex cnode p 3)
begin = (GetRykolVertexPos cnode vbegin)
end = (GetRykolVertexPos cnode vend)
ref = (GetRykolVertexPos cnode vref)
normal = (cross (end - begin) (ref - begin))
normal = (normalize normal)
rotnormal = (point3 0 0 0)
if (normal.z > 0.9) then
(
--print "x normal"
rotnormal = (normal * (rotateXMatrix -90))
)
else
(
normal.z = 0
normal = (normalize normal)
rotnormal = (normal * (rotateZMatrix -90))
)
--print rotnormal
-- print normal
-- print rotnormal
-- print begin
-- print end
dir = (normalize (end - begin))
-- print dir
score1 = (dot dir rotnormal)
RykolTurnPatch cnode cmod (p)
vbegin = (NeLGetPatchVertex cnode p 1)
vend = (NeLGetPatchVertex cnode p 2)
begin = (GetRykolVertexPos cnode vbegin)
end = (GetRykolVertexPos cnode vend)
dir = (normalize (end - begin))
score2 = (dot dir rotnormal)
RykolTurnPatch cnode cmod (p)
vbegin = (NeLGetPatchVertex cnode p 1)
vend = (NeLGetPatchVertex cnode p 2)
begin = (GetRykolVertexPos cnode vbegin)
end = (GetRykolVertexPos cnode vend)
dir = (normalize (end - begin))
score3 = (dot dir rotnormal)
RykolTurnPatch cnode cmod (p)
vbegin = (NeLGetPatchVertex cnode p 1)
vend = (NeLGetPatchVertex cnode p 2)
begin = (GetRykolVertexPos cnode vbegin)
end = (GetRykolVertexPos cnode vend)
dir = (normalize (end - begin))
score4 = (dot dir rotnormal)
-- print score1
-- print score2
-- print score3
-- print score4
if (score1 > score2 and score1 > score3 and score1 > score4) then
(
-- print "score 1"
RykolTurnPatch cnode cmod (p)
)
else if (score2 > score3 and score2 > score4) then
(
-- print "score 2"
RykolTurnPatch cnode cmod (p)
RykolTurnPatch cnode cmod (p)
)
else if (score3 > score4) then
(
-- print "score 3"
RykolTurnPatch cnode cmod (p)
RykolTurnPatch cnode cmod (p)
RykolTurnPatch cnode cmod (p)
)
else
(
-- print "score 4"
)
)
maxOps.CollapseNode cnode off
max select none
)
)
)
max select none
clearselection()
undo off
(
for cnode in nodes do
(
selectmore cnode
)
)

View file

@ -0,0 +1,68 @@
-- This script sets proper centered zone positions and generates their names
-- Use after cutting the zone into 160m by 160m pieces
cell_size = 160.0
offset_x = 7680 / 2
offset_y = -(20480 + (5120 / 2))
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-- http://proofofprogress.blogspot.be/2011/03/solution-align-pivot-to-world-without.html
Function alignPivotToWorld &theObject = (
--VLM = Visible Local Matrix.
--The matrix/pivot you see when selecting object and "Local" axis is selected as viewable.
VLM = theObject.Transform;
IP_LocalRot = theObject.objectOffsetRot; --Rotation to be used later.
IP_LOCAL = theObject.objectOffsetPos; --Invisible Pivot Local coordinates
--In relation to VLM matrix.
IP_WORLD = IP_LOCAL * VLM; --World Coordinates of Invisible Pivot. [Local To World Transform]
VLM_0 = matrix3 1; --Reset Visible Local matrix coordinates.
NEW_IP_LOCAL = IP_WORLD * inverse(VLM_0); --[World To local Transform]
theObject.Transform = VLM_0;
theObject.objectOffsetPos = NEW_IP_LOCAL;
--Now Handle Rotation:
--Since rotation of visible local matrix has been zeroed out,
--You must add that loss to the invisible pivot rotation.
GeomWorldRot = VLM.RotationPart + IP_LocalRot;
theObject.objectOffsetRot = GeomWorldRot;
)
-- Convert a coordinate in a name
-- name = coordToName #(x, y)
fn coordToName coord =
(
up = floor(coord[1] / 26) + 1
down = floor(coord[1] - ((up-1) * 26)) + 1
return (((-coord[2] + 1) as integer) as string) + "_" + alphabet[up] + alphabet[down]
)
fn realCoordToName coord =
(
return coordToName(#(((coord[1] + offset_x) / cell_size) + 0.5, ((coord[2] + offset_y) / cell_size) + 0.5))
)
fn roundedCoord coord =
(
return #(ceil(coord[1] / cell_size) * cell_size - (cell_size / 2), ceil(coord[2] / cell_size) * cell_size - (cell_size / 2))
)
max select none
clearselection()
for node in geometry do
(
if (classof node) == RklPatch or (classof node) == Editable_Patch then
(
newcoords = roundedCoord(#(node.center.x, node.center.y))
newname = realCoordToName(newcoords)
node.name = newname
alignPivotToWorld &node
node.pivot.x = newcoords[1]
node.pivot.y = newcoords[2]
resetxform node
maxOps.CollapseNode node off
)
)

View file

@ -0,0 +1,162 @@
-- Use to take the snapshots of a large manually created zone
from_x = 160
size_x = 7680-320
from_y = -25600+160
size_y = 5120-320
targetdir = "W:/database/landscape/ligo/asteroids/max"
snapshotdir = "W:/database/landscape/ligo/asteroids/zonebitmaps"
zonename = "anne"
resumeonly = true
cell_size = 160.0
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
fn lowercase instring = -- beginning of function definition
(
local upper, lower, outstring -- declare variables as local
upper="ABCDEFGHIJKLMNOPQRSTUVWXYZ" -- set variables to literals
lower="abcdefghijklmnopqrstuvwxyz"
outstring=copy instring
for i=1 to outstring.count do
(
j=findString upper outstring[i]
if (j != undefined) do outstring[i]=lower[j]
)
return outstring -- value of outstring will be returned as function result
)
fn existFile fname = (getfiles fname).count != 0
-- Convert a coordinate in a name
-- name = coordToName #(x, y)
fn coordToName coord =
(
up = floor(coord[1] / 26) + 1
down = floor(coord[1] - ((up-1) * 26)) + 1
return (((-coord[2] + 1) as integer) as string) + "_" + alphabet[up] + alphabet[down]
)
fn roundedCoord coord =
(
return #(ceil(coord[1] / cell_size) * cell_size - (cell_size / 2), ceil(coord[2] / cell_size) * cell_size - (cell_size / 2))
)
fn coordId coord =
(
coordr = (roundedCoord coord)
return #(((coordr[1]) / cell_size) + 0.5, ((coordr[2]) / cell_size) + 0.5)
)
from_coord = (coordId #(from_x, from_y))
to_coord = (coordId #(from_x + size_x, from_y + size_y))
print from_coord
print to_coord
print (coordToName from_coord)
undo off
(
for x=from_coord[1] to to_coord[1] do
(
for y=from_coord[2] to to_coord[2] do
(
ny=y+1
sy=y-1
ex=x+1
wx=x-1
zc = coordToName #(x, y)
zn = coordToName #(x, ny)
zne = coordToName #(ex, ny)
ze = coordToName #(ex, y)
zse = coordToName #(ex, sy)
zs = coordToName #(x, sy)
zsw = coordToName #(wx, sy)
zw = coordToName #(wx, y)
znw = coordToName #(wx, ny)
maxc = targetdir + "/zonematerial-" + zonename + "-" + (lowercase zc) + ".max"
csnapfile = snapshotdir + "/" + zonename + "-" + (lowercase zc) + ".tga"
if existFile maxc and (not resumeonly or not (existFile csnapfile)) then
(
print zc
resetMAXFile #noprompt
gc()
mergeMAXFile maxc #(zc)
ccenter = getnodebyname zc
maxn = targetdir + "/zonematerial-" + zonename + "-" + (lowercase zn) + ".max"
if existFile maxn then
(
mergeMAXFile maxn #(zn)
cnode = getnodebyname zn
cnode.position.y = cnode.position.y + 160
NeLAttachPatchMesh cnode ccenter
)
maxne = targetdir + "/zonematerial-" + zonename + "-" + (lowercase zne) + ".max"
if existFile maxne then
(
mergeMAXFile maxne #(zne)
cnode = getnodebyname zne
cnode.position.x = cnode.position.x + 160
cnode.position.y = cnode.position.y + 160
NeLAttachPatchMesh cnode ccenter
)
maxe = targetdir + "/zonematerial-" + zonename + "-" + (lowercase ze) + ".max"
if existFile maxe then
(
mergeMAXFile maxe #(ze)
cnode = getnodebyname ze
cnode.position.x = cnode.position.x + 160
NeLAttachPatchMesh cnode ccenter
)
maxse = targetdir + "/zonematerial-" + zonename + "-" + (lowercase zse) + ".max"
if existFile maxse then
(
mergeMAXFile maxse #(zse)
cnode = getnodebyname zse
cnode.position.x = cnode.position.x + 160
cnode.position.y = cnode.position.y - 160
NeLAttachPatchMesh cnode ccenter
)
maxs = targetdir + "/zonematerial-" + zonename + "-" + (lowercase zs) + ".max"
if existFile maxs then
(
mergeMAXFile maxs #(zs)
cnode = getnodebyname zs
cnode.position.y = cnode.position.y - 160
NeLAttachPatchMesh cnode ccenter
)
maxsw = targetdir + "/zonematerial-" + zonename + "-" + (lowercase zsw) + ".max"
if existFile maxsw then
(
mergeMAXFile maxsw #(zsw)
cnode = getnodebyname zsw
cnode.position.x = cnode.position.x - 160
cnode.position.y = cnode.position.y - 160
--NeLAttachPatchMesh cnode ccenter
)
maxw = targetdir + "/zonematerial-" + zonename + "-" + (lowercase zw) + ".max"
if existFile maxw then
(
mergeMAXFile maxw #(zw)
cnode = getnodebyname zw
cnode.position.x = cnode.position.x - 160
NeLAttachPatchMesh cnode ccenter
)
maxnw = targetdir + "/zonematerial-" + zonename + "-" + (lowercase znw) + ".max"
if existFile maxnw then
(
mergeMAXFile maxnw #(znw)
cnode = getnodebyname znw
cnode.position.x = cnode.position.x - 160
cnode.position.y = cnode.position.y + 160
NeLAttachPatchMesh cnode ccenter
)
NeLWeldPatchMesh ccenter 1.0
NeLLigoMakeSnapShot ccenter csnapfile 0 1 0 1 false
)
)
)
)

View file

@ -885,7 +885,7 @@ void Browse::OnChangeVariety()
void Browse::OnBatchLoad ()
{
CFileDialog sFile (true, NULL, NULL, OFN_ENABLESIZING,
"Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL);
"PNG Bitmap (*.png)|*.png|Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL);
if (sFile.DoModal()==IDOK)
{
@ -1365,7 +1365,7 @@ void Browse::OnExportBorder()
{
// Select a file
CFileDialog sFile (false, NULL, NULL, OFN_ENABLESIZING,
"Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL);
"PNG Bitmap (*.png)|*.png|Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL);
if (sFile.DoModal()==IDOK)
{
// Get the border of the bank
@ -1431,7 +1431,7 @@ void Browse::OnImportBorder()
{
// Select a file
CFileDialog sFile (true, NULL, NULL, OFN_ENABLESIZING,
"Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL);
"PNG Bitmap (*.png)|*.png|Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL);
if (sFile.DoModal()==IDOK)
{
// Get the border of the bank

View file

@ -1,4 +1,4 @@
FILE(GLOB SRC *.cpp *.h PIC/*.cpp PIC/*.h)
FILE(GLOB SRC *.cpp *.h)
FILE(GLOB SRC2 cpu.cpp DllEntry.cpp Popup.* thread_win32.* TileCtrl.* TileList.* TileView.*)
LIST(REMOVE_ITEM SRC ${SRC2})

View file

@ -1,126 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <stdarg.h>
#define PIC_ERRSIZE 256
static unsigned long PIC_Sys_MEM_Allocated;
static unsigned long PIC_Sys_MEM_NbAllocs;
// ----------------------------------------------------------------------------------------------------------------------------------
void *Pic_malloc(unsigned long size)
{
void *mem;
mem=malloc(size);
if (mem)
{
PIC_Sys_MEM_Allocated+=size;
PIC_Sys_MEM_NbAllocs++;
}
return(mem);
}
// -----
void *Pic_calloc(unsigned long count, unsigned long size)
{
void *mem;
mem=calloc(count,size);
if (mem)
{
PIC_Sys_MEM_Allocated+=(size*count);
PIC_Sys_MEM_NbAllocs++;
}
return(mem);
}
// -----
void Pic_free(void *memblock)
{
unsigned long size;
size=(unsigned long)_msize(memblock);
PIC_Sys_MEM_Allocated-=size;
PIC_Sys_MEM_NbAllocs--;
free(memblock);
}
// -----
unsigned long Pic__msize(void *memblock)
{
return(unsigned long)(_msize(memblock));
}
// -----
unsigned long PIC_GetMemNbAllocs(void)
{
return(PIC_Sys_MEM_NbAllocs);
}
// -----
unsigned long PIC_GetMemAllocated(void)
{
return(PIC_Sys_MEM_Allocated);
}
// ----------------------------------------------------------------------------------------------------------------------------------
static char PIC_ErrorFlag;
static char PIC_ErrorString[PIC_ERRSIZE];
static unsigned char PIC_Sys_FnctActive=0;
static void (*PIC_Sys_Fnct)(void);
void Pic_SetError(const char *msg, ...)
{
char curerr[PIC_ERRSIZE],olderr[PIC_ERRSIZE];
va_list args;
va_start(args,msg);
vsprintf(curerr,msg,args);
va_end(args);
if ( (strlen(curerr)+strlen(PIC_ErrorString))>PIC_ERRSIZE ) return;
if (PIC_ErrorFlag)
{
strcpy(olderr,PIC_ErrorString);
sprintf(PIC_ErrorString,"--- [PIC#%03d] :\n%s",PIC_ErrorFlag,curerr);
strcat(PIC_ErrorString,"\n");
strcat(PIC_ErrorString,olderr);
}
else
{
sprintf(PIC_ErrorString,"--- [PIC#%03d] :\n%s",PIC_ErrorFlag,curerr);
}
PIC_ErrorFlag++;
if (PIC_Sys_FnctActive) PIC_Sys_Fnct();
return;
}
// -----
char* PIC_GetError(void)
{
return(PIC_ErrorString);
}
// -----
unsigned char PIC_Error(void)
{
return(PIC_ErrorFlag);
}
// -----
void PIC_ResetError(void)
{
strcpy(PIC_ErrorString,"");
PIC_ErrorFlag=0;
}
// -----
unsigned char PIC_OnErrorCall( void pFnct(void) )
{
if (pFnct != NULL)
{
PIC_Sys_Fnct=pFnct;
PIC_Sys_FnctActive=1;
}
else
{
PIC_Sys_FnctActive=0;
}
return(1);
}
// ----------------------------------------------------------------------------------------------------------------------------------

View file

@ -1,215 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pic_private.h"
#include "pic.h"
// ----------------------------------------------------------------------------------------------------------------------------------
#pragma pack(1)
typedef struct BMP_HEADER
{
unsigned short bfType;
unsigned long bfSize;
unsigned short Res1;
unsigned short Res2;
unsigned long bfOffBits;
unsigned long biSize;
unsigned long biWidth;
unsigned long biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned long biCompression;
unsigned long biSizeImage;
unsigned long biXPelsPerMeter;
unsigned long biYPelsPerMeter;
unsigned long biClrUsed;
unsigned long biClrImportant;
} BMP_HEADER;
#pragma pack()
// ----------------------------------------------------------------------------------------------------------------------------------
unsigned long Pic_BMP_Write( const char *FileName,
char *pPal, char *pDatas,
unsigned long w, unsigned long h, unsigned long d)
{
FILE *file;
BMP_HEADER bmph;
unsigned long slsize;
unsigned char *scanline;
unsigned long i;
long x,y,rest;
unsigned char r,g,b;
file=fopen(FileName,"wb");
if (!file)
{
return(0);
}
memset(&bmph,0,sizeof(BMP_HEADER));
bmph.bfType=19778;
bmph.bfSize=sizeof(BMP_HEADER);
bmph.bfSize+=w*h*d/8;
if (pPal)
{
bmph.bfSize+=(256*4);
}
bmph.bfOffBits=sizeof(BMP_HEADER);
if (pPal)
{
bmph.bfOffBits+=(256*4);
}
bmph.biSize=40;//sizeof(BMP_HEADER);
bmph.biWidth=w;
bmph.biHeight=h;
bmph.biPlanes=1;
bmph.biBitCount=(unsigned short)d;
bmph.biCompression=0;
bmph.biSizeImage=w*h*d/8;
fwrite(&bmph,1,sizeof(BMP_HEADER),file);
if (pPal)
{
for(i=0 ; i<256 ; i++)
{
fwrite(&pPal[i*3+0],1,1,file);
fwrite(&pPal[i*3+1],1,1,file);
fwrite(&pPal[i*3+2],1,1,file);
fwrite(&pPal[i*3+2],1,1,file);
}
}
slsize=w*d/8;
scanline=(unsigned char*)Pic_calloc(1,slsize);
if (!scanline)
{
Pic_SetError("BMP_Write, not enough memory for scanline");
return(0);
}
for(rest=0 ; ((w*d/8)+rest)%4!=0 ; rest++);
for(y=0 ; y<(long)h ; y++)
{
memcpy(scanline,&pDatas[(h-y-1)*slsize],slsize);
if (d==24)
{
for(x=0 ; x<(long)w ; x++)
{
b=scanline[x*3+0];
g=scanline[x*3+1];
r=scanline[x*3+2];
scanline[x*3+0]=b;
scanline[x*3+1]=g;
scanline[x*3+2]=r;
}
}
fwrite(scanline,1,slsize,file);
if (rest)
{
fwrite(scanline,1,rest,file);
}
}
Pic_free(scanline);
fclose(file);
return(1);
}
// ----------------------------------------------------------------------------------------------------------------------------------
unsigned long Pic_BMP_Read( const char *FileName,
char **ppPal, char **ppDatas,
unsigned long *pWidth, unsigned long *pHeight,
unsigned long *pDepth)
{
FILE *file;
BMP_HEADER bmph;
char *pPal;
char *pDatas;
unsigned char *scanline;
long w,h,d;
long i,x,y,rest;
unsigned char r,g,b;
unsigned char pad[4];
pPal=NULL;
pDatas=NULL;
file=fopen(FileName,"rb");
if (!file)
{
Pic_SetError("BMP_Read, unable to open %s",FileName);
return(0);
}
fread(&bmph,1,sizeof(BMP_HEADER),file);
*pWidth=w=bmph.biWidth;
*pHeight=h=bmph.biHeight;
*pDepth=d=bmph.biBitCount;
if (d!=8 && d!=24)
{
Pic_SetError("BMP_Read, number of bits per pixel unsupported");
return(0);
}
if (*pDepth==8)
{
pPal=(char*)Pic_calloc(1,256*3);
if (!pPal)
{
Pic_SetError("BMP_Read, not enough memory for palette");
return(0);
}
for(i=0 ; i<256 ; i++)
{
fread(&pPal[i*3+2],1,1,file);
fread(&pPal[i*3+1],1,1,file);
fread(&pPal[i*3+0],1,1,file);
fread(&pad[0],1,1,file);
}
}
pDatas=(char*)Pic_calloc(1,w*h*d/8);
if (!pDatas)
{
if (pPal)
{
Pic_free(pPal);
}
Pic_SetError("BMP_Read, not enough memory for datas");
return(0);
}
scanline=(unsigned char*)Pic_calloc(1,w*h*d/8);
if (!scanline)
{
if (pPal)
{
Pic_free(pPal);
}
Pic_free(pDatas);
Pic_SetError("BMP_Read, not enough memory for scanline");
return(0);
}
for(rest=0 ; (w+rest)%4!=0 ; rest++);
for(y=0 ; y<h ; y++)
{
fread(scanline,w,d/8,file);
if (d==24)
{
for(x=0 ; x<w ; x++)
{
r=scanline[x*3+0];
g=scanline[x*3+1];
b=scanline[x*3+2];
scanline[x*3+0]=b;
scanline[x*3+1]=g;
scanline[x*3+2]=r;
}
}
memcpy(&pDatas[(h-y-1)*w*d/8],scanline,w*d/8);
fread(pad,rest,d/8,file);
}
fclose(file);
Pic_free(scanline);
*ppPal=pPal;
*ppDatas=pDatas;
return(1);
}
// ----------------------------------------------------------------------------------------------------------------------------------

View file

@ -1,160 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
#include <string.h>
#include <jpeglib.h>
#include "pic_private.h"
#include "pic.h"
// ----------------------------------------------------------------------------------------------------------------------------------
struct my_error_mgr
{
struct jpeg_error_mgr pub;
jmp_buf setjmp_buffer;
};
typedef struct my_error_mgr * my_error_ptr;
// ----------------------------------------------------------------------------------------------------------------------------------
static unsigned char error;
// ----------------------------------------------------------------------------------------------------------------------------------
void my_error_exit(j_common_ptr cinfo)
{
my_error_ptr myerr = (my_error_ptr) cinfo->err;
error=1;
longjmp(myerr->setjmp_buffer, 1);
}
// ----------------------------------------------------------------------------------------------------------------------------------
unsigned long Pic_JPG_Read(const char *FileName, char **ppPal, char **ppDatas, unsigned long *w, unsigned long *h)
{
struct jpeg_decompress_struct cinfo;
struct my_error_mgr jerr;
FILE *file;
JSAMPARRAY buffer;
int row_stride,i;
char *pDatas,*pPal;
unsigned long ptr;
error=0;
ptr=0;
file=fopen(FileName, "rb");
if (!file)
{
Pic_SetError("JPG_Read, unable to open %s",FileName);
return(0);
}
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
setjmp(jerr.setjmp_buffer);
if (error)
{
Pic_SetError("JPG_Read, internal decompression error");
jpeg_destroy_decompress(&cinfo);
return(0);
}
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, file);
(void) jpeg_read_header(&cinfo, TRUE);
*w=cinfo.image_width;
*h=cinfo.image_height;
if (!ppPal)
{
pDatas=(char*)Pic_calloc(1,(*w)*(*h)*3);
}
else
{
pDatas=(char*)Pic_calloc(1,(*w)*(*h));
pPal=(char*)Pic_calloc(1,256*3);
if (!pPal)
{
Pic_SetError("JPG_Read, not enough memory for palette");
return(0);
}
cinfo.desired_number_of_colors = 256;
cinfo.quantize_colors = TRUE;
cinfo.dither_mode = JDITHER_ORDERED;
}
if (!pDatas)
{
Pic_SetError("JPG_Read, not enough memory for pic");
return(0);
}
(void) jpeg_start_decompress(&cinfo);
row_stride = cinfo.output_width * cinfo.output_components;
buffer = (*cinfo.mem->alloc_sarray)
((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
while (cinfo.output_scanline < cinfo.output_height)
{
(void) jpeg_read_scanlines(&cinfo, buffer, 1);
memcpy(&pDatas[ptr],buffer[0],row_stride);
ptr+=row_stride;
}
*ppDatas=pDatas;
if (ppPal)
{
for(i=0 ; i<256 ; i++)
{
pPal[i*3+0]=cinfo.colormap[2][i];
pPal[i*3+1]=cinfo.colormap[1][i];
pPal[i*3+2]=cinfo.colormap[0][i];
}
*ppPal=pPal;
}
(void) jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
fclose(file);
return(1);
}
// ----------------------------------------------------------------------------------------------------------------------------------
unsigned long Pic_JPG_Write(const char *FileName, unsigned long Qual, char *pDatas, unsigned long w, unsigned long h)
{
struct jpeg_compress_struct cinfo;
struct my_error_mgr jerr;
FILE *file;
JSAMPROW row_pointer[1];
int row_stride;
error=0;
file=fopen(FileName,"wb");
if (!file)
{
Pic_SetError("JPG_Write, unable to open %s",FileName);
return(0);
}
jpeg_create_compress(&cinfo);
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
setjmp(jerr.setjmp_buffer);
if (error)
{
Pic_SetError("JPG_Write, internal compression error");
jpeg_destroy_compress(&cinfo);
return(0);
}
jpeg_stdio_dest(&cinfo, file);
cinfo.image_width = w;
cinfo.image_height = h;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, Qual, TRUE);
jpeg_start_compress(&cinfo, TRUE);
row_stride = w * 3;
while(cinfo.next_scanline<cinfo.image_height)
{
row_pointer[0] = (JSAMPROW)& pDatas[cinfo.next_scanline * row_stride];
(void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
}
jpeg_finish_compress(&cinfo);
fclose(file);
jpeg_destroy_compress(&cinfo);
return(1);
}

View file

@ -1,637 +0,0 @@
#include <string.h>
#include "pic_private.h"
#include "pic.h"
static unsigned long NbPics=0;
static PIC_PICTURE *HeadPic=NULL;
// ----------------------------------------------------------------------------------------------------------------------------------
static PIC_PICTURE *GetPic(unsigned long id)
{
PIC_PICTURE *pic;
for(pic=HeadPic ; pic ; pic=pic->Next)
{
if (pic->ID==id)
{
return(pic);
}
}
return(NULL);
}
// ----------------------------------------------------------------------------------------------------------------------------------
unsigned long PIC_Load(char* FileName, unsigned char Quantize)
{
char ext[4];
unsigned long type;
unsigned long i,taken,id;
PIC_PICTURE *pic;
char *pDatas;
char *pPal;
unsigned long w,h,Depth;
unsigned long ret;
// --- Init
ret=0;
type=0;
id=0;
taken=0;
w=0;
h=0;
Depth=0;
pic=NULL;
pDatas=NULL;
pPal=NULL;
// --- Get 1st available ID
for(i=1 ; i<=NbPics+1 ; i++)
{
taken=0;
for(pic=HeadPic ; pic ; pic=pic->Next)
{
if (pic->ID==i)
{
taken=1;
break;
}
}
if (!taken)
{
id=i;
break;
}
}
if (!id)
{
Pic_SetError("Load, unable to create ID");
return(0);
}
// --- Load pic
if (FileName)
{
ext[0]=FileName[strlen(FileName)-3];
ext[1]=FileName[strlen(FileName)-2];
ext[2]=FileName[strlen(FileName)-1];
ext[3]=0;
strupr(ext);
if ( !strcmp(ext,"JPG") )
{
type=1;
}
else if ( !strcmp(ext,"TGA") )
{
type=2;
}
else if ( !strcmp(ext,"BMP") )
{
type=3;
}
switch(type)
{
// - JPG
case 1:
if (!Quantize)
{
Depth=24;
ret=Pic_JPG_Read(FileName,NULL,&pDatas,&w,&h);
}
else
{
Depth=8;
ret=Pic_JPG_Read(FileName,&pPal,&pDatas,&w,&h);
}
if (!ret)
{
Pic_SetError("Load, unable to load JPG file %s",FileName);
return(0);
}
break;
// - TGA
case 2:
ret=Pic_TGA_Read(FileName,&pPal,&pDatas,&w,&h,&Depth);
if (!ret)
{
Pic_SetError("Load, unable to load TGA file %s",FileName);
return(0);
}
break;
// - BMP
case 3:
ret=Pic_BMP_Read(FileName,&pPal,&pDatas,&w,&h,&Depth);
if (!ret)
{
Pic_SetError("Load, unable to load BMP file %s",FileName);
return(0);
}
break;
// - Unknown
default:
Pic_SetError("Load, unknown extension for %s",FileName);
return(0);
}
}
// --- Create and place new pic struct
pic=(PIC_PICTURE *)Pic_calloc(1,sizeof(PIC_PICTURE));
if (!pic)
{
Pic_SetError("Load, not enough memory for internal structure");
return(0);
}
pic->Next=HeadPic;
HeadPic=pic;
NbPics++;
pic->ID=id;
pic->pDatas=pDatas;
pic->pPal=pPal;
pic->Width=w;
pic->Height=h;
pic->Depth=Depth;
return(id);
}
// ----------------------------------------------------------------------------------------------------------------------------------
unsigned long PIC_Create(char* pPal, char* pDatas, unsigned long w, unsigned long h, unsigned long d)
{
unsigned long i,taken,id;
PIC_PICTURE *pic;
// --- Init
id=0;
taken=0;
pic=NULL;
// --- Get 1st available ID
for(i=1 ; i<=NbPics+1 ; i++)
{
taken=0;
for(pic=HeadPic ; pic ; pic=pic->Next)
{
if (pic->ID==i)
{
taken=1;
break;
}
}
if (!taken)
{
id=i;
break;
}
}
if (!id)
{
Pic_SetError("Create, unable to create ID");
return(0);
}
// --- Create pic
if (!pDatas)
{
pDatas=(char *)Pic_calloc(1,w*h*d/8);
if (!pDatas)
{
Pic_SetError("Create, not enough memory for datas");
return(0);
}
}
if (d==8)
{
if (!pPal)
{
pPal=(char *)Pic_calloc(1,256*3);
if (!pPal)
{
Pic_SetError("Create, not enough memory for palette");
return(0);
}
}
}
else
{
pPal=NULL;
}
// --- Create and place new pic struct
pic=(PIC_PICTURE *)Pic_calloc(1,sizeof(PIC_PICTURE));
if (!pic)
{
Pic_SetError("Create, not enough memory for internal structure");
return(0);
}
pic->Next=HeadPic;
HeadPic=pic;
NbPics++;
pic->ID=id;
pic->pDatas=pDatas;
pic->pPal=pPal;
pic->Width=w;
pic->Height=h;
pic->Depth=d;
return(id);
}
// ----------------------------------------------------------------------------------------------------------------------------------
unsigned long PIC_GetInfos( unsigned long id,
char **ppPal, char **ppDatas,
unsigned long *pW, unsigned long *pH, unsigned long *pD)
{
PIC_PICTURE *pic;
pic=GetPic(id);
if (!pic)
{
Pic_SetError("GetInfos, picture internal structure not found");
return(0);
}
if (ppPal)
{
*ppPal=pic->pPal;
}
if (ppDatas)
{
*ppDatas=pic->pDatas;
}
if (pW)
{
*pW=pic->Width;
}
if (pH)
{
*pH=pic->Height;
}
if (pD)
{
*pD=pic->Depth;
}
return(id);
}
// ----------------------------------------------------------------------------------------------------------------------------------
static char* Conv8To24(unsigned long id)
{
PIC_PICTURE *pic;
char *buf;
unsigned long i;
pic=GetPic(id);
if (!pic)
{
Pic_SetError("Conv8To24, picture internal structure not found");
return(NULL);
}
buf=(char *)Pic_malloc(pic->Width*pic->Height*3);
if (!buf)
{
Pic_SetError("Conv8To24, not enough memory for temporary buffer");
return(NULL);
}
for(i=0 ; i<pic->Width*pic->Height ; i++)
{
buf[i*3+0]=pic->pPal[pic->pDatas[i]*3+0];
buf[i*3+1]=pic->pPal[pic->pDatas[i]*3+1];
buf[i*3+2]=pic->pPal[pic->pDatas[i]*3+2];
}
return(buf);
}
// ----------------------------------------
static char* Conv8To16(unsigned long id)
{
PIC_PICTURE *pic;
unsigned short *buf;
unsigned long i;
unsigned short r,g,b,pix16;
pic=GetPic(id);
if (!pic)
{
Pic_SetError("Conv8To24, picture internal structure not found");
return(NULL);
}
buf=(unsigned short*)Pic_malloc(pic->Width*pic->Height*2);
if (!buf)
{
Pic_SetError("Conv8To24, not enough memory for temporary buffer");
return(NULL);
}
for(i=0 ; i<pic->Width*pic->Height ; i++)
{
b=pic->pPal[pic->pDatas[i]*3+0];
g=pic->pPal[pic->pDatas[i]*3+1];
r=pic->pPal[pic->pDatas[i]*3+2];
r>>=3;
g>>=3; g&=0x3E;
b>>=3;
pix16=(r<<10)+(g<<5)+b;
buf[i]=pix16;
}
return (char*)buf;
}
// ----------------------------------------
static char* Conv16To24(unsigned long id)
{
PIC_PICTURE *pic;
unsigned short *pDatas;
unsigned char *buf;
unsigned long i;
unsigned short r,g,b;
pic=GetPic(id);
if (!pic)
{
Pic_SetError("Conv16To24, picture internal structure not found");
return(NULL);
}
buf=(unsigned char *)Pic_malloc(pic->Width*pic->Height*3);
if (!buf)
{
Pic_SetError("Conv16To24, not enough memory for temporary buffer");
return(NULL);
}
pDatas=(unsigned short*)pic->pDatas;
for(i=0 ; i<pic->Width*pic->Height ; i++)
{
r=(pDatas[i] & 0x7C00)>>(10-3);
g=(pDatas[i] & 0x03E0)>>(5-3);
b=(pDatas[i] & 0x001F)<<3;
buf[i*3+0]=(unsigned char)r;
buf[i*3+1]=(unsigned char)g;
buf[i*3+2]=(unsigned char)b;
}
return (char*)buf;
}
// ----------------------------------------
static char* Conv24To16(unsigned long id)
{
PIC_PICTURE *pic;
unsigned short *buf;
unsigned long i;
unsigned short r,g,b;
unsigned short pix16;
pic=GetPic(id);
if (!pic)
{
Pic_SetError("Conv24To16, picture internal structure not found");
return(NULL);
}
buf=(unsigned short*)Pic_malloc(pic->Width*pic->Height*2);
if (!buf)
{
Pic_SetError("Conv24To16, not enough memory for temporary buffer");
return(NULL);
}
for(i=0 ; i<pic->Width*pic->Height ; i++)
{
r=pic->pDatas[i*3+0];
g=pic->pDatas[i*3+1];
b=pic->pDatas[i*3+2];
// r : 5 bits forts (0x7C)
// g : 5 bits (6e zapped) (0x3E)
// b : 5 bits faibles (0x1F)
r>>=3;
g>>=3; g&=0x3E;
b>>=3;
pix16=(r<<10)+(g<<5)+b;
buf[i]=pix16;
}
return (char*)buf;
}
// ----------------------------------------
static char* ConvPic(PIC_PICTURE *pic, unsigned long type, char* pErr)
{
char *buf;
unsigned long src,dst;
*pErr=0;
buf=NULL;
src=pic->Depth;
if (type==PIC_TYPE_TGA8 || type==PIC_TYPE_BMP8)
{
dst=8;
}
if (type==PIC_TYPE_TGA16)
{
dst=16;
}
if (type==PIC_TYPE_JPG || type==PIC_TYPE_TGA24 || type==PIC_TYPE_BMP24)
{
dst=24;
}
// ---
if (src==dst)
{
return(NULL);
}
// ---
if (src==8 && dst==24)
{
buf=Conv8To24(pic->ID);
if (!buf)
{
*pErr=1;
}
return(buf);
}
if (src==8 && dst==16)
{
buf=Conv8To16(pic->ID);
if (!buf)
{
*pErr=1;
}
return(buf);
}
// ---
if (src==16 && dst==24)
{
buf=Conv16To24(pic->ID);
if (!buf)
{
*pErr=1;
}
return(buf);
}
// ---
if (src==24 && dst==16)
{
buf=Conv24To16(pic->ID);
if (!buf)
{
*pErr=1;
}
return buf;
}
// ---
if (src==24 && dst==8)
{
Pic_SetError("ConvPic, downsampling 24 to 8 bits unsupported");
*pErr=1;
return(NULL);
}
Pic_SetError("ConvPic, conversion %d to %d unsupported",src,dst);
*pErr=1;
return(NULL);
}
// ----------------------------------------
unsigned long PIC_Save(unsigned long id, char* FileName, unsigned long type, unsigned long qual)
{
PIC_PICTURE *pic;
char err;
char *buf;
char *freeit;
unsigned long depth;
freeit=NULL;
pic=GetPic(id);
if (!pic)
{
Pic_SetError("Save %s, picture internal structure not found",FileName);
return(0);
}
freeit = ConvPic(pic,type,&err);
if (err)
{
Pic_SetError("Save %s, error while converting picture",FileName);
return(0);
}
if (!freeit)
{
buf=pic->pDatas;
}
else
{
buf=freeit;
}
err=0;
switch(type)
{
// ---
case PIC_TYPE_JPG:
if ( !Pic_JPG_Write(FileName,qual,buf,pic->Width,pic->Height) )
{
if (freeit)
{
Pic_free(buf);
}
Pic_SetError("Save %s, error while saving JPG file",FileName);
err=1;
}
break;
// ---
case PIC_TYPE_TGA8:
case PIC_TYPE_TGA16:
case PIC_TYPE_TGA24:
if (type==PIC_TYPE_TGA8)
{
depth=8;
}
if (type==PIC_TYPE_TGA16)
{
depth=16;
}
if (type==PIC_TYPE_TGA24)
{
depth=24;
}
if ( !Pic_TGA_Write(FileName,pic->pPal,buf,pic->Width,pic->Height,depth) )
{
if (freeit)
{
Pic_free(freeit);
}
Pic_SetError("Save %s, error while saving TGA file",FileName);
err=1;
}
break;
// ---
case PIC_TYPE_BMP8:
case PIC_TYPE_BMP24:
if (type==PIC_TYPE_BMP8)
{
depth=8;
}
if (type==PIC_TYPE_BMP24)
{
depth=24;
}
if ( !Pic_BMP_Write(FileName,pic->pPal,buf,pic->Width,pic->Height,depth) )
{
if (freeit)
{
Pic_free(freeit);
}
Pic_SetError("Save %s, error while saving BMP file",FileName);
err=1;
}
break;
// ---
default:
Pic_SetError("Save %s, unknow save format/type",FileName);
err=1;
break;
}
if (freeit)
{
Pic_free(freeit);
}
return(err-1);
}
// ----------------------------------------------------------------------------------------------------------------------------------
unsigned long PIC_Destroy(unsigned long id)
{
PIC_PICTURE *prevpic,*pic;
unsigned long found;
prevpic=NULL;
found=0;
for(pic=HeadPic ; pic ; pic=pic->Next)
{
if (pic->ID==id)
{
found=1;
break;
}
prevpic=pic;
}
if (!found)
{
Pic_SetError("Destroy, picture internal structure not found");
return(0);
}
if (prevpic)
{
prevpic->Next=pic->Next;
}
if (pic->pDatas)
{
Pic_free(pic->pDatas);
}
if (pic->pPal)
{
Pic_free(pic->pPal);
}
if (pic==HeadPic)
{
HeadPic=pic->Next;
}
Pic_free(pic);
return(1);
}
// ----------------------------------------------------------------------------------------------------------------------------------

View file

@ -1,215 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pic_private.h"
#include "pic.h"
// ----------------------------------------------------------------------------------------------------------------------------------
#pragma pack(1)
typedef struct TGA_HEADER
{
unsigned char LengthID;
unsigned char CMapType;
unsigned char ImageType;
unsigned short Origin;
unsigned short Length;
unsigned char Depth;
unsigned short XOrg;
unsigned short YOrg;
unsigned short Width;
unsigned short Height;
unsigned char ImageDepth;
unsigned char Desc;
} TGA_HEADER;
#pragma pack()
// ----------------------------------------------------------------------------------------------------------------------------------
unsigned long Pic_TGA_Read( const char *FileName,
char **ppPal, char **ppDatas,
unsigned long *pWidth, unsigned long *pHeight,
unsigned long *pDepth)
{
FILE *file;
TGA_HEADER tgah;
long w,h,d;
unsigned long size;
char *pDatas;
char *pPal;
long x,y;
long slsize;
unsigned char *scanline;
unsigned char r,g,b;
long i;
int upSideDown;
pDatas=NULL;
pPal=NULL;
file=fopen(FileName,"rb");
if (!file)
{
Pic_SetError("TGA_Read, unable to open %s",FileName);
return(0);
}
fread(&tgah,1,sizeof(TGA_HEADER),file);
if (tgah.ImageType>3)
{
Pic_SetError("TGA_Read, unsupported TGA format");
return(0);
}
*pWidth=w=tgah.Width;
*pHeight=h=tgah.Height;
*pDepth=d=tgah.ImageDepth;
upSideDown = ((tgah.Desc & (1 << 5))==0);
size=tgah.Width*tgah.Height*(tgah.ImageDepth/8);
pDatas=(char*)Pic_malloc(size);
if (!pDatas)
{
Pic_SetError("TGA_Read, not enough memory");
return(0);
}
if (*pDepth==8)
{
if (!ppPal)
{
Pic_free(pDatas);
Pic_SetError("TGA_Read, need a pointer to palette");
return(0);
}
pPal=(char*)Pic_calloc(1,256*3);
if (!pPal)
{
Pic_SetError("TGA_Read, not enough memory for palette");
return(0);
}
if (tgah.ImageType==1)
{
for(i=0 ; i<256*3 ; i+=3)
{
fread(&pPal[i+2],1,1,file);
fread(&pPal[i+1],1,1,file);
fread(&pPal[i+0],1,1,file);
}
}
*ppPal=pPal;
}
slsize=w*d/8;
scanline=(unsigned char*)Pic_calloc(1,slsize);
if (!scanline)
{
if (pPal)
{
Pic_free(pPal);
}
Pic_free(pDatas);
Pic_SetError("TGA_Read, not enough memory for scanline");
return(0);
}
for(y=0 ; y<h ; y++)
{
fread(scanline,1,slsize,file);
if (d==24 || d==32)
{
long mult=3;
if(d==32) mult=4;
for(x=0 ; x<w ; x++)
{
r=scanline[x*mult+0];
g=scanline[x*mult+1];
b=scanline[x*mult+2];
scanline[x*mult+0]=b;
scanline[x*mult+1]=g;
scanline[x*mult+2]=r;
}
}
if (upSideDown)
memcpy(&pDatas[(h-y-1)*slsize], scanline, slsize);
else
memcpy(&pDatas[(y)*slsize], scanline, slsize);
}
Pic_free(scanline);
fclose(file);
*ppDatas=pDatas;
return(1);
}
// ----------------------------------------------------------------------------------------------------------------------------------
unsigned long Pic_TGA_Write( const char *FileName,
char *pPal, char *pDatas,
unsigned long w, unsigned long h, unsigned long d)
{
FILE *file;
TGA_HEADER tgah;
long x,y;
long slsize;
unsigned char *scanline;
unsigned char r,g,b;
file=fopen(FileName,"wb");
if (!file)
{
Pic_SetError("TGA_Write, unable to open %s",FileName);
return(0);
}
memset(&tgah,0,sizeof(TGA_HEADER));
tgah.LengthID=0;
if (d>8)
{
tgah.CMapType=0;
tgah.ImageType=2;
tgah.Length=0;
tgah.Depth=0;
}
else
{
tgah.CMapType=1;
tgah.ImageType=1;
tgah.Length=256;
tgah.Depth=24;
}
tgah.Origin=0;
tgah.XOrg=0;
tgah.YOrg=0;
tgah.Width=(unsigned short)w;
tgah.Height=(unsigned short)h;
tgah.ImageDepth=(unsigned char)d;
tgah.Desc=0;
fwrite(&tgah,1,sizeof(TGA_HEADER),file);
if (d==8)
{
fwrite(pPal,1,256*3,file);
}
slsize=w*d/8;
scanline=(unsigned char*)Pic_calloc(1,slsize);
if (!scanline)
{
Pic_SetError("TGA_Write, not enough memory for scanline");
return(0);
}
for(y=0 ; y<(long)h ; y++)
{
memcpy(scanline,&pDatas[(h-y-1)*slsize],slsize);
if (d==24)
{
for(x=0 ; x<(long)w ; x++)
{
r=scanline[x*3+0];
g=scanline[x*3+1];
b=scanline[x*3+2];
scanline[x*3+0]=b;
scanline[x*3+1]=g;
scanline[x*3+2]=r;
}
}
fwrite(scanline,1,slsize,file);
}
Pic_free(scanline);
fclose(file);
return(1);
}

View file

@ -1,58 +0,0 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _PIC_H_
#define _PIC_H_
// ----------------------------------------------------------------------------------------------------------------------------------
#define PIC_TYPE_JPG 1
#define PIC_TYPE_TGA8 2
#define PIC_TYPE_TGA16 3
#define PIC_TYPE_TGA24 4
#define PIC_TYPE_BMP8 5
#define PIC_TYPE_BMP24 6
// ----------------------------------------------------------------------------------------------------------------------------------
//
// Basic API
//
extern unsigned long PIC_Load(char* FileName, unsigned char Quantize);
extern unsigned long PIC_Create(char* pPal, char* pDatas, unsigned long w, unsigned long h, unsigned long d);
extern unsigned long PIC_Save(unsigned long id, char* FileName, unsigned long type, unsigned long qual);
extern unsigned long PIC_GetInfos( unsigned long id,
char **ppPal, char **ppDatas,
unsigned long *pW, unsigned long *pH, unsigned long *pD);
extern unsigned long PIC_Destroy(unsigned long id);
//
// System
//
extern unsigned long PIC_GetMemNbAllocs(void);
extern unsigned long PIC_GetMemAllocated(void);
extern char* PIC_GetError(void);
extern unsigned char PIC_Error(void);
extern void PIC_ResetError(void);
extern unsigned char PIC_OnErrorCall( void pFnct(void) );
// ----------------------------------------------------------------------------------------------------------------------------------
#endif

View file

@ -1,81 +0,0 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _PIC_PRIVATE_H_
#define _PIC_PRIVATE_H_
// ----------------------------------------------------------------------------------------------------------------------------------
typedef struct PIC_PICTURE
{
unsigned long ID;
unsigned long Width;
unsigned long Height;
unsigned long Depth;
char *pDatas;
char *pPal;
struct PIC_PICTURE *Next;
} PIC_PICTURE;
// ----------------------------------------------------------------------------------------------------------------------------------
//
// JPG
//
extern unsigned long Pic_JPG_Read( const char *FileName,
char **ppPal, char **ppDatas,
unsigned long *w, unsigned long *h);
extern unsigned long Pic_JPG_Write( const char *FileName,
unsigned long Qual,
char *pDatas,
unsigned long w, unsigned long h);
//
// TGA
//
extern unsigned long Pic_TGA_Read( const char *FileName,
char **ppPal, char **ppDatas,
unsigned long *pWidth, unsigned long *pHeight,
unsigned long *pDepth);
extern unsigned long Pic_TGA_Write( const char *FileName,
char *pPal, char *pDatas,
unsigned long w, unsigned long h, unsigned long d);
//
// BMP
//
extern unsigned long Pic_BMP_Read( const char *FileName,
char **ppPal, char **ppDatas,
unsigned long *pWidth, unsigned long *pHeight,
unsigned long *pDepth);
extern unsigned long Pic_BMP_Write( const char *FileName,
char *pPal, char *pDatas,
unsigned long w, unsigned long h, unsigned long d);
//
// System
//
extern void* Pic_malloc(unsigned long size);
extern void* Pic_calloc(unsigned long count, unsigned long size);
extern void Pic_free(void *memblock);
extern unsigned long Pic__msize(void *memblock);
extern void Pic_SetError(const char *msg, ...);
// ----------------------------------------------------------------------------------------------------------------------------------
#endif

View file

@ -1,84 +0,0 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <assert.h>
#include <algorithm>
#include "readpic.h"
#include "pic.h"
#include <nel/misc/rgba.h>
using namespace std;
//============================================================
// Image API.
//============================================================
bool PIC_LoadPic(string path, vector<NLMISC::CBGRA> &tampon, uint &Width, uint &Height)
{
uint32 id;
char *pal, *data;
unsigned long w,h,depth;
uint i;
// Loadons l'image.
id= PIC_Load((char*)path.c_str(), 0);
if(id==0)
return false;
PIC_GetInfos( id, &pal, &data, &w, &h, &depth);
Width=w;
Height=h;
// On traduit en RGBA.
tampon.resize(w*h);
switch(depth)
{
case 8:
for(i=0;i<w*h;i++)
{
tampon[i].R= data[i];
tampon[i].G= data[i];
tampon[i].B= data[i];
tampon[i].A= data[i];
}
break;
case 24:
for(i=0;i<w*h;i++)
{
tampon[i].R= data[i*3+ 0];
tampon[i].G= data[i*3+ 1];
tampon[i].B= data[i*3+ 2];
tampon[i].A= 255;
}
break;
case 32:
for(i=0;i<w*h;i++)
{
tampon[i].R= data[i*4+ 0];
tampon[i].G= data[i*4+ 1];
tampon[i].B= data[i*4+ 2];
tampon[i].A= data[i*4+ 3];
}
break;
}
// On ferme.
PIC_Destroy(id);
return true;
}

View file

@ -1,40 +0,0 @@
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _READPIC_H_
#define _READPIC_H_
#ifdef _MSC_VER
#pragma warning(disable:4786)
#endif
#include <string>
#include <vector>
#include <nel/misc/types_nl.h>
#include <nel/misc/rgba.h>
//============================================================
// API.
//============================================================
bool PIC_LoadPic(std::string Path, std::vector<NLMISC::CBGRA> &Tampon, uint &Width, uint &Height);
#endif

View file

@ -24,7 +24,7 @@
#include <direct.h>
//#include "ListGroup.h"
//#include "ViewPopup.h"
#include "pic/readpic.h"
//#include "pic/readpic.h"
using namespace std;
using namespace NL3D;
@ -74,6 +74,37 @@ void rotateBuffer (uint &Width, uint &Height, std::vector<NLMISC::CBGRA>& Tampon
Height=tmp;
}
static bool loadPic(const string &path, std::vector<NLMISC::CBGRA> &tampon, uint &width, uint &height)
{
try
{
NLMISC::CIFile file;
if (file.open(path.c_str()))
{
NLMISC::CBitmap bitmap;
bitmap.load(file);
width = bitmap.getWidth();
height = bitmap.getHeight();
tampon.resize(width * height);
bitmap.convertToType(NLMISC::CBitmap::RGBA);
for (uint y = 0; y < height; ++y)
{
for (uint x = 0; x < width; ++x)
{
NLMISC::CRGBA c = bitmap.getPixelColor(x, y, 0);
c.R = (c.R * c.A) / 255;
c.G = (c.G * c.A) / 255;
c.B = (c.B * c.A) / 255;
tampon[(y * width) + x] = c;
}
}
return true;
}
}
catch (NLMISC::Exception& ) { }
return false;
}
/////////////////////////////////////////////////////////////////////////////
// CTView
//Attention : windows veut que le buffer image commence du bas vers le haut
@ -82,7 +113,7 @@ int _LoadBitmap(const std::string& path,LPBITMAPINFO BitmapInfo, std::vector<NLM
//vector<NLMISC::CBGRA> Tampon;
uint Width;
uint Height;
if (PIC_LoadPic(path, Tampon, Width, Height))
if (loadPic(path, Tampon, Width, Height))
{
BitmapInfo->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
BitmapInfo->bmiHeader.biWidth=Width;
@ -207,7 +238,7 @@ int TileList::setTile128 (int tile, const std::string& name, NL3D::CTile::TBitma
vector<NLMISC::CBGRA> tampon;
uint Width;
uint Height;
if (!PIC_LoadPic(tileBank2.getAbsPath ()+troncated, tampon, Width, Height))
if (!loadPic(tileBank2.getAbsPath ()+troncated, tampon, Width, Height))
{
return (int)(MessageBox (NULL, ((tileBank2.getAbsPath ()+troncated)+"\nContinue ?").c_str(), "Can't load bitmap.", MB_YESNO|MB_ICONEXCLAMATION)==IDYES);
}
@ -272,7 +303,7 @@ int TileList::setTile256 (int tile, const std::string& name, NL3D::CTile::TBitma
vector<NLMISC::CBGRA> tampon;
uint Width;
uint Height;
if (!PIC_LoadPic(tileBank2.getAbsPath ()+troncated, tampon, Width, Height))
if (!loadPic(tileBank2.getAbsPath ()+troncated, tampon, Width, Height))
{
return (int)(MessageBox (NULL, ((tileBank2.getAbsPath ()+troncated)+"\nContinue ?").c_str(), "Can't load bitmap.", MB_YESNO|MB_ICONEXCLAMATION)==IDYES);
}
@ -338,7 +369,7 @@ int TileList::setTileTransition (int tile, const std::string& name, NL3D::CTile:
vector<NLMISC::CBGRA> tampon;
uint Width;
uint Height;
if (!PIC_LoadPic(tileBank2.getAbsPath ()+troncated, tampon, Width, Height))
if (!loadPic(tileBank2.getAbsPath ()+troncated, tampon, Width, Height))
{
return (int)(MessageBox (NULL, ((tileBank2.getAbsPath ()+troncated)+"\nContinue ?").c_str(), "Can't load bitmap.", MB_YESNO|MB_ICONEXCLAMATION)==IDYES);
}
@ -451,7 +482,7 @@ int TileList::setTileTransitionAlpha (int tile, const std::string& name, int rot
vector<NLMISC::CBGRA> tampon;
uint Width;
uint Height;
if (!PIC_LoadPic(tileBank2.getAbsPath ()+troncated, tampon, Width, Height))
if (!loadPic(tileBank2.getAbsPath ()+troncated, tampon, Width, Height))
{
return MessageBox (NULL, ((tileBank2.getAbsPath ()+troncated)+"\nContinue ?").c_str(), "Can't load bitmap.", MB_YESNO|MB_ICONEXCLAMATION)==IDYES;
}
@ -1490,7 +1521,7 @@ LRESULT CTView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
_chdir (LastPath.c_str());
CFileDialog load(true, NULL, LastPath.c_str(), OFN_ENABLESIZING | OFN_ALLOWMULTISELECT,
"Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL);
"PNG Bitmap (*.png)|*.png|Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL);
load.m_ofn.lpstrFile = new char[10000]; // buffer contains filenames list
load.m_ofn.lpstrFile[0] = 0;
// with 10 KB we should be large enough...

View file

@ -187,6 +187,8 @@ fn haveCoarseMesh node =
return false
)
fn getRoot node = if isvalidnode node.parent then getRoot node.parent else node
fn runNelMaxExportSub inputMaxFile retryCount =
(
tagThisFile = false
@ -273,55 +275,51 @@ fn runNelMaxExportSub inputMaxFile retryCount =
-- For each node
for node in array_node do
(
-- It is root ?
if (node.parent == undefined) then
-- Is not a skeleton ?
if (((substring node.name 1 3) != "Bip") and ((substring (getRoot node).name 1 3) != "Bip")) then
(
-- Is not a skeleton ?
if (node.name != "Bip01") then
-- Can be exported ?
if (isToBeExported node == true) then
(
-- Can be exported ?
if (isToBeExported node == true) then
-- Not a lod ?
if ((isLod node) == false) then
(
-- Not a lod ?
if ((isLod node) == false) then
-- Output directory
if (haveCoarseMesh node) == true then
output = ("%OutputDirectoryWithCoarseMesh%/" + (node.name) + ".shape")
else
output = ("%OutputDirectoryWithoutCoarseMesh%/" + (node.name) + ".shape")
-- Compare file date
if (NeLTestFileDate output inputMaxFile) == true then
(
-- Output directory
if (haveCoarseMesh node) == true then
output = ("%OutputDirectoryWithCoarseMesh%/" + (node.name) + ".shape")
else
output = ("%OutputDirectoryWithoutCoarseMesh%/" + (node.name) + ".shape")
-- Compare file date
if (NeLTestFileDate output inputMaxFile) == true then
try
(
try
-- Export the shape
if (NelExportShapeEx node output %ShapeExportOptShadow% %ShapeExportOptExportLighting% "%OutputDirectoryLightmap%" %ShapeExportOptLightingLimit% %ShapeExportOptLumelSize% %ShapeExportOptOversampling% true false %ShapeExportOptLightmapLog%) == true then
(
-- Export the shape
if (NelExportShapeEx node output %ShapeExportOptShadow% %ShapeExportOptExportLighting% "%OutputDirectoryLightmap%" %ShapeExportOptLightingLimit% %ShapeExportOptLumelSize% %ShapeExportOptOversampling% true false %ShapeExportOptLightmapLog%) == true then
(
nlerror("OK "+output)
exported = exported +1
)
else
(
-- Error
nlerror("ERROR exporting shape " + node.name + " in file " + inputMaxFile)
tagThisFile = false
)
nlerror("OK "+output)
exported = exported +1
)
catch
else
(
-- Error
nlerror("ERROR fatal error exporting shape " + node.name + " in file " + inputMaxFile)
nlerror("ERROR exporting shape " + node.name + " in file " + inputMaxFile)
tagThisFile = false
)
)
else
catch
(
nlerror("SKIPPED " + output)
exported = exported + 1
-- Error
nlerror("ERROR fatal error exporting shape " + node.name + " in file " + inputMaxFile)
tagThisFile = false
)
)
else
(
nlerror("SKIPPED " + output)
exported = exported + 1
)
)
)
)

View file

@ -253,6 +253,8 @@ fn haveCoarseMesh node =
return false
)
fn getRoot node = if isvalidnode node.parent then getRoot node.parent else node
fn runNelMaxExportSub inputMaxFile retryCount =
(
tagThisFile = false
@ -339,55 +341,51 @@ fn runNelMaxExportSub inputMaxFile retryCount =
-- For each node
for node in array_node do
(
-- It is root ?
if (node.parent == undefined) then
-- Is not a skeleton ?
if (((substring node.name 1 3) != "Bip") and ((substring (getRoot node).name 1 3) != "Bip")) then
(
-- Is not a skeleton ?
if (node.name != "Bip01") then
-- Can be exported ?
if (isToBeExported node == true) then
(
-- Can be exported ?
if (isToBeExported node == true) then
-- Not a lod ?
if ((isLod node) == false) then
(
-- Not a lod ?
if ((isLod node) == false) then
-- Output directory
if (haveCoarseMesh node) == true then
output = ("%OutputDirectoryWithCoarseMesh%/" + (node.name) + ".shape")
else
output = ("%OutputDirectoryWithoutCoarseMesh%/" + (node.name) + ".shape")
-- Compare file date
if (NeLTestFileDate output inputMaxFile) == true then
(
-- Output directory
if (haveCoarseMesh node) == true then
output = ("%OutputDirectoryWithCoarseMesh%/" + (node.name) + ".shape")
else
output = ("%OutputDirectoryWithoutCoarseMesh%/" + (node.name) + ".shape")
-- Compare file date
if (NeLTestFileDate output inputMaxFile) == true then
try
(
try
-- Export the shape
if (NelExportShapeEx node output %ShapeExportOptShadow% %ShapeExportOptExportLighting% "%OutputDirectoryLightmap%" %ShapeExportOptLightingLimit% %ShapeExportOptLumelSize% %ShapeExportOptOversampling% true false %ShapeExportOptLightmapLog%) == true then
(
-- Export the shape
if (NelExportShapeEx node output %ShapeExportOptShadow% %ShapeExportOptExportLighting% "%OutputDirectoryLightmap%" %ShapeExportOptLightingLimit% %ShapeExportOptLumelSize% %ShapeExportOptOversampling% true false %ShapeExportOptLightmapLog%) == true then
(
nlerror("OK "+output)
exported = exported +1
)
else
(
-- Error
nlerror("ERROR exporting shape " + node.name + " in file " + inputMaxFile)
tagThisFile = false
)
nlerror("OK "+output)
exported = exported +1
)
catch
else
(
-- Error
nlerror("ERROR fatal error exporting shape " + node.name + " in file " + inputMaxFile)
nlerror("ERROR exporting shape " + node.name + " in file " + inputMaxFile)
tagThisFile = false
)
)
else
catch
(
nlerror("SKIPPED " + output)
exported = exported + 1
-- Error
nlerror("ERROR fatal error exporting shape " + node.name + " in file " + inputMaxFile)
tagThisFile = false
)
)
else
(
nlerror("SKIPPED " + output)
exported = exported + 1
)
)
)
)

View file

@ -0,0 +1,11 @@
title Ryzom Core: 1_export.py (LEVELDESIGN)
1_export.py -ipj common/sky common/sfx common/gamedev common/data_common common/data_shard common/leveldesign common/exedll common/cfg shard/data_shard shard/data_language shard/data_leveldesign shard/data_game_share
title Ryzom Core: 2_build.py (LEVELDESIGN)
2_build.py -ipj common/sky common/sfx common/gamedev common/data_common common/data_shard common/leveldesign common/exedll common/cfg shard/data_shard shard/data_language shard/data_leveldesign shard/data_game_share
title Ryzom Core: 3_install.py (LEVELDESIGN)
3_install.py -ipj common/sky common/sfx common/gamedev common/data_common common/data_shard common/leveldesign common/exedll common/cfg shard/data_shard shard/data_language shard/data_leveldesign shard/data_game_share
title Ryzom Core: b1_client_dev.py (LEVELDESIGN)
b1_client_dev.py
title Ryzom Core: b2_shard_data.py (LEVELDESIGN)
b2_shard_data.py
title Ryzom Core: Ready

View file

@ -371,6 +371,9 @@ void displayDebug()
// Current GameCycle
TextContext->printfAt(1.f, line, "Ms per Cycle : %d", NetMngr.getMsPerTick());
line += lineStep;
// Smoothed Client Date
TextContext->printfAt(1.f, line, "Smoothed Client Date : %u %f", SmoothedClientDate.Day, SmoothedClientDate.Hour);
line += lineStep;
// Packet Loss
TextContext->printfAt(1.f, line, "Packet Loss : %.1f %%", NetMngr.getMeanPacketLoss()*100.0f);
line += lineStep;

View file

@ -235,7 +235,7 @@ uint CSky::setup(const CClientDate &date, const CClientDate &animationDate, floa
// animate objects
if (_PlayListManager)
{
double globalDate = ((double) _NumHourInDay * date.Day + (double) date.Hour) / _NumHourInDay;
double globalDate = (double)date.Hour / (double)_NumHourInDay;
//nlinfo("global date = %f", (float) globalDate);
_PlayListManager->animate(_AnimLengthInSeconds * globalDate);
}

View file

@ -20,7 +20,7 @@
#define RYZOM_VERSION "ryzomcore" \
"/" \
"v0.11.2" \
""
"-dev"
#endif // RYZOM_VERSION_H

View file

@ -20,8 +20,18 @@ class Ticket_User{
* @param $permission the permission that will be given to the user. 1=user, 2=mod, 3=admin
*/
public static function createTicketUser( $extern_id, $permission) {
$dbl = new DBLayer("lib");
$dbl->insert("ticket_user",array('TUserId' => $extern_id, 'Permission' => $permission, 'ExternId' => $extern_id));
try {
//make connection with and put into db
$dbl = new DBLayer("lib");
$dbl->insert("ticket_user",array('TUserId' => $extern_id, 'Permission' => $permission, 'ExternId' => $extern_id));
}
catch (PDOException $e) {
//oh noooz...
//error_log(print_r($e, true));
//print_r($e);
echo "Problem creating user in database!";
}
}

View file

@ -0,0 +1,2 @@
INSERT INTO `settings` (`idSettings`, `Setting`, `Value`) VALUES
(2, 'Domain_Auto_Add', '1');

View file

@ -6,7 +6,7 @@ $db_nel_tool = 2;
// Support
$db_nel_ams = 2;
$db_nel_ams_lib = 6;
$db_nel_ams_lib = 7;
// Domain
$db_ring_domain = 1;

View file

@ -42,6 +42,20 @@ require_once('setup/version.php');
$continue = false;
}
}
if ($continue) {
try {
if (!in_array("mysql",PDO::getAvailableDrivers(),TRUE))
{
throw new PDOException ("Cannot work without a proper database setting up");
}
}
catch (PDOException $pdoEx)
{
printalert("danger", "PHP PDO seems to be missing the mysql driver");
$continue = false;
}
}
// Validate basics
if ($continue) {